简体   繁体   English

如何使用Java中的LinkedBlockingQueue创建线程池?

[英]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.

相关问题 java 如何为 stream 操作创建线程池 - java how to create thread pool for stream operation 如何在Java中创建一个线程池,以便在每次运行时创建一个新线程? - How can I create a thread pool in Java that creates a new thread on each run? 如何在Java中创建一个不能同时运行某些任务的线程池? - How can I create a thread pool in Java that does not run certain tasks concurrently? Java并发性:我可以使用辅助线程创建池吗? - Java Concurrency: Can I create a pool using worker thread 如何懒惰地创建供Java线程池使用的任务 - How to lazily create tasks for use by a Java thread-pool 使用LinkedBlockingQueue时,如何给使用者优先级? - How do I give priority to Consumers when using a LinkedBlockingQueue? 如何使用同步来订购LinkedBlockingQueue? - How do I use synchronization to order my LinkedBlockingQueue? 如何使用公用池创建连接池? - How do I create a pool of connection using commons pool? 如何创建Java Web Start应用程序的线程转储 - How do I create a thread dump of a Java Web Start application 如何创建一个新线程以Java语言绘制到屏幕上? - How do I create a new thread(s) that draws to the screen in Java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM