ThreadPoolExecutor implementation question

Discussion in 'Java' started by allen@rrsg.ee.uct.ac.za, Oct 4, 2005.

  1. Guest

    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/EDU/oswego/cs/dl/util/concurrent/PooledExecutor.java
    I see that PooledExecutor.execute uses a synchronized block which would
    prevent the above case from occuring.

    Am I missing something?

    cheers
    Allen
     
    , Oct 4, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marc E
    Replies:
    0
    Views:
    692
    Marc E
    Apr 29, 2006
  2. Maciej
    Replies:
    1
    Views:
    681
    Thomas Hawtin
    Oct 27, 2006
  3. Replies:
    11
    Views:
    21,393
  4. pksiazek
    Replies:
    2
    Views:
    1,654
    pksiazek
    Oct 15, 2007
  5. Philipp

    ThreadPoolExecutor backport

    Philipp, Jul 31, 2008, in forum: Java
    Replies:
    6
    Views:
    995
Loading...

Share This Page