[英]How do I create a Thread Pool with a LinkedBlockingQueue in Java?
How do I create a Thread Pool with a LinkedBlockingQueue in Java? 如何使用Java中的LinkedBlockingQueue创建线程池? I am using this to download files from the internet.
我正在使用它从互联网下载文件。 I just need the general pattern.
我只需要一般模式。
ThreadPoolExecutor
has various constructors that take a BlockingQueue
argument. ThreadPoolExecutor
具有采用BlockingQueue
参数的各种构造函数。 There are several other parameters, though, and you'll need to pick the ones appropriate for your problem. 但是,还有其他几个参数,您需要选择适合您问题的参数。
Here is one demo : 这是一个演示:
public static ExecutorService newLinkedBlockingQueueThreadPool() {
return new ThreadPoolExecutor(0, Integer.MAX_VALUE,
60L, TimeUnit.SECONDS,
new LinkedBlockingQueue<Runnable>());
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.