简体   繁体   中英

core pool size 0 and unbounded linkedblockingqueue

Hi i am new to java and learning about concurrency. I saw the following code below. I ran the code and noticed only 1 thread is being used even though i concurrently submmited 100 task. What does it mean for corepoolsize = 0 with LinkedBlockedQueue (unbounded) and my maxpool is 120. thanks.

public static ThreadPoolExecutor generatetThreadPool() {

    ThreadFactory factory = new ThreadFactoryBuilder().setNameFormat("thread-%d")
        .build();
    return new ThreadPoolExecutor(0, 120, 3, TimeUnit.MINUTES,
        new LinkedBlockingQueue<>(), factory);
  }

From the Javadoc for ThreadPoolExecutor :

corePoolSize – the number of threads to keep in the pool, even if they are idle,
    unless allowCoreThreadTimeOut is set

So when corePoolSize is zero, threads will terminate when keepAliveTime passes, and no new threads will be created to replace them until needed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM