Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > ThreadPoolExecutor implementation question

Reply
Thread Tools

ThreadPoolExecutor implementation question

 
 
allen@rrsg.ee.uct.ac.za
Guest
Posts: n/a
 
      10-04-2005
Hi,
I have a question about Sun's implementation of
java.util.concurrent.ThreadPoolExecutor, specifically the execute(
Runnable ) method. The runState field is read before the Runnable task
is added to the workQueue (BlockingQueue), however there is no
synchronization in place. It seems that it might be possible for
another thread to invoke shutdown after runState is checked, but before
the task is added to the queue. Is it not then possible that the queue
is cleared by the shutdown process, the executor left as terminated,
only for the task to finally be added to the queue, something like:

Thread 1 | Thread 2
execute( t1 ) |
runState==RUNNING |
| shutdown
| runState=SHUTDOWN
| clear out workQueue
| return
| executor now terminated
|
workQueue.add(t1) |
return |

At this point, t1 is stuck in a queue that will never be cleared, but
no feedback to that effect was given on Thread 1.

Looking at Doug Lea's PooledExecutor at
http://gee.cs.oswego.edu/dl/classes/...dExecutor.java
I see that PooledExecutor.execute uses a synchronized block which would
prevent the above case from occuring.

Am I missing something?

cheers
Allen

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ThreadPoolExecutor backport Philipp Java 6 07-31-2008 07:32 PM
Holding threads after timeout (ThreadPoolExecutor) pksiazek Java 2 10-15-2007 02:41 PM
ThreadPoolExecutor with blocking execute? castillo.bryan@gmail.com Java 11 12-20-2006 05:14 PM
Suspending threads by ThreadPoolExecutor Maciej Java 1 10-27-2006 02:08 PM
looking for good guide to using ThreadPoolExecutor Marc E Java 0 04-29-2006 03:13 PM



Advertisments