views:

49

answers:

1

I am using TheadPoolExecutor that executes on a PriorityQueue. I have set a minimum pool size of 5 and max of 50. When we ran the load test, we saw like 10% jump is CPU. The thread dump shows

pool-1-thread-5" prio=3 tid=0x020f69a0 nid=0xa3 waiting on condition [0xb517f000..0xb517f970] at sun.misc.Unsafe.park(Native Method) at java.util.concurrent.locks.LockSupport.park(LockSupport.java:118) at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:1841) at java.util.concurrent.PriorityBlockingQueue.take(PriorityBlockingQueue.java:200) at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:470) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675) at java.lang.Thread.run(Thread.java:595)

Wondering the prestartAllCoreThreads() that I use in ThreadPoolExecutor will have any performance issue?

TIA

A: 

The sun.misc.Unsafe.park method is where the threads that are created by the ThreadPoolExecutor will wait until new messages are received. Internally the ThreadPoolExecutor has a queue of Runnables that it will farm out to waiting threads. If your system is idle or reasonably quiet, expect to see quite a few threads waiting in this method.

If you are profiling a system, this method will often crop up as a key consumer of time. This is expected if most of the time the threads is waiting for work to do.

Michael Barker
Profiling typically shows CPU time...no? I mean, I agree, if you were to continuously poll the Thread's current stack, most of the real life time is likely spent waiting for new tasks in most systems.
Tim Bender