Name: rmT116609 Date: 02/08/2004
FULL PRODUCT VERSION :
java version "1.5.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b32c)
Java HotSpot(TM) Client VM (build 1.5.0-beta-b32c, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
A java.util.concurrent thread pool may consume cpu after all work has been done. I'm seeing 100% CPU usage after completing all jobs.
Thread dumps reveal that one thread sometimes is to be seen awake, checking its interruption status when it should be parked and sleeping:
"pool-1-thread-2" prio=5 tid=0x008edca0 nid=0x984 runnable [0x0135f000..0x0135fb
68]
at java.lang.Thread.isInterrupted(Native Method)
at java.lang.Thread.interrupted(Unknown Source)
at java.util.concurrent.locks.ReentrantLock$ConditionObject.await(Unknow
n Source)
at java.util.concurrent.LinkedBlockingQueue.take(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.getTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.access+100(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the testcase with a fair number of threads. On my machine '10' is always sufficient, sometimes '3' are enough.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The program should print a decreasing sequence of numbers and then remain idle.
ACTUAL -
The program prints a decreasing sequence of numbers and then consumes 100% CPU.
REPRODUCIBILITY :
This bug can be reproduced often.
---------- BEGIN SOURCE ----------
import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicInteger;
public class ThreadPool {
public static void main(String[] args) {
int n = Integer.parseInt(args[0]);
final AtomicInteger todo = new AtomicInteger(2*n);
ExecutorService p = Executors.newFixedThreadPool(n);
for(int i=0; i<2*n; i++) {
p.execute(new Runnable() { public void run() {
System.out.println(todo.decrementAndGet());
}});
}
}
}
---------- END SOURCE ----------
(Incident Review ID: 237713)
======================================================================