[concurrency-interest] ThreadPoolExecutor goes below corePoolSize

Moran Avigdor moran at gigaspaces.com
Tue Jun 3 05:33:36 EDT 2008


 

I remember there was a problem in 6.0, but I wasn't aware of problems in
1.5 in this regard.

Thank you for the replies - this obviously answers my question.

 

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6458662

 

 

________________________________

From: Moran Avigdor 
Sent: Monday, June 02, 2008 1:22 PM
To: concurrency-interest at cs.oswego.edu
Subject: [concurrency-interest] ThreadPoolExecutor goes below
corePoolSize

 

Hi,

I searched a bit on bugs opened related to corePoolSize, but did not
find a related post 

regarding corePoolThreads being removed from the cache, although they
shouldn't.

 

My test case below simulates a ThreadPool, which is constructed with a
min corePoolSize and a max pool size.

The idle wait time is set to 1 ms. I block my threads with a
CountDownLatch to ensure that threads scale from min to max (and are not
reused).

By releasing the latch I free up all the threads to complete their work,
and check that we did not go below core pool size.

 

This test sometimes fails on the assertion that we are below
corePoolSize:

junit.framework.AssertionFailedError: Expected minimum pool size.
expected:<2> but was:<1>

 

Is anyone familiar with such a scenario?

 

I am using JDK 1.5.0_12.

Regards,

Moran Avigdor

 

 

 

    public void testScaleDown() throws Exception {

        final int min = 2;

        final int max = 4;

        final CountDownLatch active = new CountDownLatch(max +1);

        

        ThreadPoolExecutor pool =
(ThreadPoolExecutor)Executors.newCachedThreadPool();

        pool.setCorePoolSize(min);

        pool.setMaximumPoolSize(max);

        pool.setKeepAliveTime(1, TimeUnit.MILLISECONDS);

 

        for (int i=0; i<max; ++i) {

            pool.execute( new Runnable() {

                public void run()

                {

                    try {

                        active.countDown();

                        active.await();

                    }catch (InterruptedException e) {

                        e.printStackTrace(); //ignore

                    }

                } 

            });

            //wait time to execute task by pool

            Thread.sleep(100);

        }

        

        Assert.assertEquals("Expected all threads to block. ", 1,
active.getCount());

        Assert.assertEquals("Expected active. ", max,
pool.getActiveCount());

        Assert.assertEquals("Expected max pool size. ", max,
pool.getPoolSize());

 

        //release the latch

        active.countDown();

        active.await();

        

        //wait around for one second for state to settle

        Thread.sleep(1000);

        Assert.assertEquals("Expected completion of all tasks. ", max,
pool.getCompletedTaskCount());

        Assert.assertEquals("Expected completion of all threads. ", 0,
pool.getActiveCount());

        Assert.assertEquals("Expected minimum pool size. ", min,
pool.getPoolSize());

    }

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/attachments/20080603/12508da4/attachment-0001.html 


More information about the Concurrency-interest mailing list