[concurrency-interest] some questions with ThreadPoolExecutor

freish freish at 163.com
Wed Aug 15 09:26:19 EDT 2012


perhaps it is really a bug.  In jdk1.7,there is no such problem.And I find that ThreadPoolExecutor is rewriten in jdk1.7.



Another problem with jdk1.6 and previous is as below:


import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
 
public class TestSetCorePoolSize {
    public static void main(String[] args) throws InterruptedException {
        final ThreadPoolExecutor pool = (ThreadPoolExecutor)Executors.newFixedThreadPool(5);
        pool.prestartAllCoreThreads();
        //waiting for threads in pool started
        new Thread(){
            public void run() {
                try {
                    Thread.sleep(6000L);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                pool.setCorePoolSize(3);
                System.out.println("set corePoolSize:3");
            }
        }.start();
        for(int i=0; i<30; i++) {
            System.out.println("poolSize:" + ((ThreadPoolExecutor)pool).getPoolSize());
            Thread.sleep(1000L);
        }
        pool.shutdown();
    }
}




after setCorePoolSize called, the pool size won't become 3. But in jdk1.7,it is 3.and this is a reasonable behavor.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20120815/478ae55c/attachment.html>


More information about the Concurrency-interest mailing list