接下来,对于另一个线程池类DatamineThread,几乎复制了完全相同的结构。
Next, you almost copy the exact same structure for the next thread pool class, DatamineThread.
分析这段代码时您可以看到,我们添加了另一个队列实例,然后将该队列传递给第一个线程池类ThreadURL。
In looking at the code, you can see that we added another instance of a queue, and then passed that queue into the first thread pool class, ThreadURL.
如果您发现您的应用程序需要线程池,那么请考虑使用ut il . concurrent中的某个executor类,例如PooledExecutor,而不用从头开始编写。
If you find yourself in need of a thread pool for your application, consider using one of the Executor classes from util.concurrent, such as PooledExecutor, rather than writing one from scratch.
使用Executors工具类来创建线程池,而不是直接调用ThreadPoolExecut or构造器来创建。
You don't call the ThreadPoolExecutor constructor directly to create a thread pool but instead use the Executors utility class to create one.
如果池类没有捕捉到它们,那么线程只会退出而线程池的大小将会永久减少一个。
If the pool class does not catch these, then the thread will simply exit and the size of the thread pool will be permanently reduced by one.
调整线程池的大小基本上就是避免两类错误:线程太少或线程太多。
Tuning the size of a thread pool is largely a matter of avoiding two mistakes: having too few threads or too many threads.
Executor类实际上充当着一个提供Executor 实现实例的共同位置,但它只有new方法(例如用于创建新线程池);它没有预先创建实例。
The Executor class does serve as a common place to get Executor-implementing instances, but it only has new methods (to create a new thread pool, for example); it doesn't have precreated instances.
该包中的PooledExecut or类是一种有效的、广泛使用的以工作队列为基础的线程池的正确实现。
The PooledExecutor class from this package is an efficient, widely used, correct implementation of a thread pool based on a work queue.
当系统中存在多个线程池时,此方法或许对于此类的扩展类在进行作业重新分配时是有用的。
This method may be useful in extensions to this class that re-assign work in systems with multiple pools.
解决方法:找到一个图书馆这样做或使用类的执行器套件和使用有限的线程池(只能下载一次)。
Solution: find a library to do this or make use of the Executor suite of classes and use a limited pool of threads (then only download a few at a time).
解决方法:找到一个图书馆这样做或使用类的执行器套件和使用有限的线程池(只能下载一次)。
Solution: find a library to do this or make use of the Executor suite of classes and use a limited pool of threads (then only download a few at a time).
应用推荐