[concurrency-interest] NullPointerException after removing all tasks from ThreadPoolExecutor

Norman Elton wnelto at wm.edu
Mon Sep 5 15:09:51 EDT 2005


I've setup a simple test scenario that is producing a  
NullPointerException. My code is...

----------------
ThreadPoolExecutor tpe = new ThreadPoolExecutor(1, 1, 5,  
TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), new  
JobThreadFactory());

tThread t1 = new tThread(1);
tThread t2 = new tThread(2);
tThread t3 = new tThread(3);

tpe.execute(t1);
tpe.execute(t2);

tpe.remove(t2);

tpe.execute(t3);
----------------

The "tThread" class merely waits five seconds and produces a simple  
message to System.out. No magic there. The code runs the first thread  
(t1) as expected, then starts spewing out exceptions of the form...

Exception in thread "EX-1737" java.lang.NullPointerException
         at java.util.concurrent.LinkedBlockingQueue.extract(Unknown  
Source)
         at java.util.concurrent.LinkedBlockingQueue.take(Unknown  
Source)
         at java.util.concurrent.ThreadPoolExecutor.getTask(Unknown  
Source)
         at java.util.concurrent.ThreadPoolExecutor$Worker.run 
(Unknown Source)
         at java.lang.Thread.run(Unknown Source)

It does not appear to like it when I remove all the tasks from the  
queue. If I leave one task on the queue, it remains happy.

Any ideas? I looked through the JSR166 bugs, and did not find  
anything that looked promising.

Thanks for your help,

Norman


More information about the Concurrency-interest mailing list