9 Replies Latest reply: Aug 26, 2011 10:02 AM by 796440 RSS

    Strange behaviour with Fixed thread pool

    861239
      Hi all

      I am trying to learn multithreading. I have written a small snippet of code. After running for around 30 minutes, this code ends up in a deadlock. I am trying to figure out a reason. any help will be really appreciated. Thanks. Following is the code. I am using Ubuntu 10.04 and jdk 1.6.
      package rollerdemo;
      
      //Simulate a roller coaster, as in exercise 3.5 of Magee and Kramer.
      
      import java.util.concurrent.CyclicBarrier;
      import java.util.concurrent.BrokenBarrierException;
      import java.util.concurrent.ExecutorService;
      import java.util.concurrent.Executors;
      
      //This thread deals with the passengers arriving at random intervals.
      
      class TurnstileBarrier implements Runnable
      {  
           private ControlBarrier controlBarrier;
           private CyclicBarrier cyclicBarrier;
      
           TurnstileBarrier(ControlBarrier controlBarrier, CyclicBarrier cyclicBarrier) {  
                this.controlBarrier = controlBarrier;
                this.cyclicBarrier = cyclicBarrier;
           }
      
           public void run(){  
                try {
                     controlBarrier.welcomePassenger();
                     cyclicBarrier.await();
                     
                } catch (InterruptedException e) { 
                     Thread.currentThread().interrupt();               
                } catch (BrokenBarrierException e) { 
                     Thread.currentThread().interrupt();               
                } finally {
                     
                }
           }
      }
      
      class RollerBarrier
      {  
           public static int NUMBER_OF_PASSENGERS_PER_CAR = 20;
           public static void main(String[] args) throws InterruptedException
           {
                final ControlBarrier controlBarrier = new ControlBarrier();
                
                Runnable carBarrier = new Runnable() {
                     public void run(){  
                          controlBarrier.departCar();
                     }
                };
                
                CyclicBarrier barrier = new CyclicBarrier(NUMBER_OF_PASSENGERS_PER_CAR, carBarrier);
      
                ExecutorService pool = Executors.newFixedThreadPool(NUMBER_OF_PASSENGERS_PER_CAR);
                while(true)
                     pool.execute(new TurnstileBarrier(controlBarrier,barrier));
      
      
                
           }
      }
      
      // The Control class represents the state of the controller, and the actions
      // which can be performed. 
      
      class ControlBarrier
      {  
           private long queued = 0;
           private long carsSent = 0;
           private long numberOfPassengersTravelledToday = 0;
           
           ControlBarrier()
           {  
                queued = 0;
                carsSent = 0;
                numberOfPassengersTravelledToday = 0;
           }
           synchronized void welcomePassenger() {
                System.out.format("Welcoming Passenger %d%n", ++queued);
                ++numberOfPassengersTravelledToday;
           }
           synchronized void departCar() {
                queued = queued - RollerBarrier.NUMBER_OF_PASSENGERS_PER_CAR;
                System.out.format("The car %d is going now and the number of passengers travelled so far with us is %d%n", ++carsSent, numberOfPassengersTravelledToday);
           }
      }
      Edited by: 858236 on May 12, 2011 2:35 AM
        • 1. Re: Strange behaviour with Fixed thread pool
          796440
          1. When posting code, use code tags so it will be readable: http://forums.oracle.com/forums/ann.jspa?annID=1429

          2. How are you certain that it's in fact a deadlock and not something else? I ask this because the term "deadlock" gets misused a lot for any situation where things seem to have stalled, but "deadlock" has a very specific meaning.
          • 2. Re: Strange behaviour with Fixed thread pool
            802316
            You don't appear to hold more than one lock at a time, so it is hard to see how you can get a dealock.

            I suggest you try
            jstack -l <pid>
            to get a thread dump listing any locking errors.
            • 3. Re: Strange behaviour with Fixed thread pool
              jtahlborn
              personally, i would advise against using a cyclic barrier. as it has been written, it's almost impossible to use in a robust fashion. if you ever get to the point where one thread gets busted, the whole thing basically locks up.
              • 4. Re: Strange behaviour with Fixed thread pool
                861239
                Thanks every one for the replies. Really very helpful. After doing the stack -l pid I have got into a confusion. It seems that there is no deadlock but why would all of a sudden the program stop to run. May be I am missing some thing. Just check the stack trace. What I read is that out of 20 threads, 3 threads are waiting on the cyclic barrier await function, while other 17 are waiting to get new tasks from the pool. Am I wrong here? Many thanks.

                2011-05-11 23:42:26
                Full thread dump OpenJDK Client VM (19.0-b09 mixed mode, sharing):
                
                "Attach Listener" daemon prio=10 tid=0x088fc000 nid=0x34d4 waiting on condition [0x00000000]
                   java.lang.Thread.State: RUNNABLE
                
                   Locked ownable synchronizers:
                     - None
                
                "DestroyJavaVM" prio=10 tid=0xb4f21c00 nid=0x2c85 waiting on condition [0x00000000]
                   java.lang.Thread.State: RUNNABLE
                
                   Locked ownable synchronizers:
                     - None
                
                "pool-1-thread-20" prio=10 tid=0xb4f20000 nid=0x2ca0 waiting on condition [0xb49ee000]
                   java.lang.Thread.State: WAITING (parking)
                     at sun.misc.Unsafe.park(Native Method)
                     - parking to wait for  <0x7a387350> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
                     at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186)
                     at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043)
                     at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:386)
                     at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1043)
                     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1103)
                     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
                     at java.lang.Thread.run(Thread.java:636)
                
                   Locked ownable synchronizers:
                     - None
                
                "pool-1-thread-19" prio=10 tid=0xb4f1e800 nid=0x2c9f waiting on condition [0xb4a3f000]
                   java.lang.Thread.State: WAITING (parking)
                     at sun.misc.Unsafe.park(Native Method)
                     - parking to wait for  <0x7a387350> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
                     at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186)
                     at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043)
                     at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:386)
                     at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1043)
                     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1103)
                     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
                     at java.lang.Thread.run(Thread.java:636)
                
                   Locked ownable synchronizers:
                     - None
                
                "pool-1-thread-18" prio=10 tid=0xb4f1d000 nid=0x2c9e waiting on condition [0xb4a90000]
                   java.lang.Thread.State: WAITING (parking)
                     at sun.misc.Unsafe.park(Native Method)
                     - parking to wait for  <0x7a387350> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
                     at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186)
                     at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043)
                     at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:386)
                     at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1043)
                     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1103)
                     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
                     at java.lang.Thread.run(Thread.java:636)
                
                   Locked ownable synchronizers:
                     - None
                
                "pool-1-thread-17" prio=10 tid=0xb4f1b800 nid=0x2c9d waiting on condition [0xb4ae1000]
                   java.lang.Thread.State: WAITING (parking)
                     at sun.misc.Unsafe.park(Native Method)
                     - parking to wait for  <0x7a387350> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
                     at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186)
                     at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043)
                     at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:386)
                     at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1043)
                     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1103)
                     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
                     at java.lang.Thread.run(Thread.java:636)
                
                   Locked ownable synchronizers:
                     - None
                
                "pool-1-thread-16" prio=10 tid=0xb4f19c00 nid=0x2c9c waiting on condition [0xb4b32000]
                   java.lang.Thread.State: WAITING (parking)
                     at sun.misc.Unsafe.park(Native Method)
                     - parking to wait for  <0x7a387350> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
                     at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186)
                     at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043)
                     at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:386)
                     at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1043)
                     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1103)
                     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
                     at java.lang.Thread.run(Thread.java:636)
                
                   Locked ownable synchronizers:
                     - None
                
                "pool-1-thread-15" prio=10 tid=0xb4f18400 nid=0x2c9b waiting on condition [0xb4b83000]
                   java.lang.Thread.State: WAITING (parking)
                     at sun.misc.Unsafe.park(Native Method)
                     - parking to wait for  <0x7a387350> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
                     at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186)
                     at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043)
                     at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:386)
                     at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1043)
                     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1103)
                     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
                     at java.lang.Thread.run(Thread.java:636)
                
                   Locked ownable synchronizers:
                     - None
                
                "pool-1-thread-14" prio=10 tid=0xb4f16c00 nid=0x2c9a waiting on condition [0xb4bd4000]
                   java.lang.Thread.State: WAITING (parking)
                     at sun.misc.Unsafe.park(Native Method)
                     - parking to wait for  <0x7a387350> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
                     at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186)
                     at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043)
                     at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:386)
                     at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1043)
                     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1103)
                     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
                     at java.lang.Thread.run(Thread.java:636)
                
                   Locked ownable synchronizers:
                     - None
                
                "pool-1-thread-13" prio=10 tid=0xb4f15400 nid=0x2c99 waiting on condition [0xb4c25000]
                   java.lang.Thread.State: WAITING (parking)
                     at sun.misc.Unsafe.park(Native Method)
                     - parking to wait for  <0x7a387350> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
                     at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186)
                     at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043)
                     at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:386)
                     at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1043)
                     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1103)
                     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
                     at java.lang.Thread.run(Thread.java:636)
                
                   Locked ownable synchronizers:
                     - None
                
                "pool-1-thread-12" prio=10 tid=0xb4f13c00 nid=0x2c98 waiting on condition [0xb4c76000]
                   java.lang.Thread.State: WAITING (parking)
                     at sun.misc.Unsafe.park(Native Method)
                     - parking to wait for  <0x7a387350> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
                     at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186)
                     at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043)
                     at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:386)
                     at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1043)
                     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1103)
                     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
                     at java.lang.Thread.run(Thread.java:636)
                
                   Locked ownable synchronizers:
                     - None
                
                "pool-1-thread-11" prio=10 tid=0xb4f12400 nid=0x2c97 waiting on condition [0xb4cc7000]
                   java.lang.Thread.State: WAITING (parking)
                     at sun.misc.Unsafe.park(Native Method)
                     - parking to wait for  <0x7a387350> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
                     at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186)
                     at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043)
                     at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:386)
                     at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1043)
                     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1103)
                     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
                     at java.lang.Thread.run(Thread.java:636)
                
                   Locked ownable synchronizers:
                     - None
                
                "pool-1-thread-10" prio=10 tid=0xb4f10c00 nid=0x2c96 waiting on condition [0xb4d18000]
                   java.lang.Thread.State: WAITING (parking)
                     at sun.misc.Unsafe.park(Native Method)
                     - parking to wait for  <0x7a387350> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
                     at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186)
                     at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043)
                     at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:386)
                     at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1043)
                     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1103)
                     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
                     at java.lang.Thread.run(Thread.java:636)
                
                   Locked ownable synchronizers:
                     - None
                
                "pool-1-thread-9" prio=10 tid=0xb4f0f400 nid=0x2c95 waiting on condition [0xb4d69000]
                   java.lang.Thread.State: WAITING (parking)
                     at sun.misc.Unsafe.park(Native Method)
                     - parking to wait for  <0x7a387350> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
                     at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186)
                     at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043)
                     at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:386)
                     at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1043)
                     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1103)
                     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
                     at java.lang.Thread.run(Thread.java:636)
                
                   Locked ownable synchronizers:
                     - None
                
                "pool-1-thread-8" prio=10 tid=0xb4f0dc00 nid=0x2c94 waiting on condition [0xb4dba000]
                   java.lang.Thread.State: WAITING (parking)
                     at sun.misc.Unsafe.park(Native Method)
                     - parking to wait for  <0x7a380108> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
                     at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186)
                     at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043)
                     at java.util.concurrent.CyclicBarrier.dowait(CyclicBarrier.java:227)
                     at java.util.concurrent.CyclicBarrier.await(CyclicBarrier.java:355)
                     at rollerdemo.TurnstileBarrier.run(RollerBarrier.java:25)
                     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
                     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
                     at java.lang.Thread.run(Thread.java:636)
                
                   Locked ownable synchronizers:
                     - <0x7a3808d8> (a java.util.concurrent.ThreadPoolExecutor$Worker)
                
                "pool-1-thread-7" prio=10 tid=0xb4f0c800 nid=0x2c93 waiting on condition [0xb4e0b000]
                   java.lang.Thread.State: WAITING (parking)
                     at sun.misc.Unsafe.park(Native Method)
                     - parking to wait for  <0x7a387350> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
                     at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186)
                     at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043)
                     at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:386)
                     at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1043)
                     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1103)
                     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
                     at java.lang.Thread.run(Thread.java:636)
                
                   Locked ownable synchronizers:
                     - None
                
                "pool-1-thread-6" prio=10 tid=0xb4f0b400 nid=0x2c92 waiting on condition [0xb4e5c000]
                   java.lang.Thread.State: WAITING (parking)
                     at sun.misc.Unsafe.park(Native Method)
                     - parking to wait for  <0x7a387350> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
                     at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186)
                     at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043)
                     at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:386)
                     at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1043)
                     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1103)
                     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
                     at java.lang.Thread.run(Thread.java:636)
                
                   Locked ownable synchronizers:
                     - None
                
                "pool-1-thread-5" prio=10 tid=0xb4f09800 nid=0x2c91 waiting on condition [0xb4ead000]
                   java.lang.Thread.State: WAITING (parking)
                     at sun.misc.Unsafe.park(Native Method)
                     - parking to wait for  <0x7a387350> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
                     at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186)
                     at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043)
                     at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:386)
                     at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1043)
                     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1103)
                     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
                     at java.lang.Thread.run(Thread.java:636)
                
                   Locked ownable synchronizers:
                     - None
                
                "pool-1-thread-4" prio=10 tid=0xb4f08400 nid=0x2c90 waiting on condition [0xb4efe000]
                   java.lang.Thread.State: WAITING (parking)
                     at sun.misc.Unsafe.park(Native Method)
                     - parking to wait for  <0x7a380108> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
                     at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186)
                     at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043)
                     at java.util.concurrent.CyclicBarrier.dowait(CyclicBarrier.java:227)
                     at java.util.concurrent.CyclicBarrier.await(CyclicBarrier.java:355)
                     at rollerdemo.TurnstileBarrier.run(RollerBarrier.java:25)
                     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
                     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
                     at java.lang.Thread.run(Thread.java:636)
                
                   Locked ownable synchronizers:
                     - <0x7a382cd0> (a java.util.concurrent.ThreadPoolExecutor$Worker)
                
                "pool-1-thread-3" prio=10 tid=0xb4f07000 nid=0x2c8f waiting on condition [0xb5053000]
                   java.lang.Thread.State: WAITING (parking)
                     at sun.misc.Unsafe.park(Native Method)
                     - parking to wait for  <0x7a387350> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
                     at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186)
                     at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043)
                     at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:386)
                     at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1043)
                     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1103)
                     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
                     at java.lang.Thread.run(Thread.java:636)
                
                   Locked ownable synchronizers:
                     - None
                
                "pool-1-thread-2" prio=10 tid=0xb4f05800 nid=0x2c8e waiting on condition [0xb50a4000]
                   java.lang.Thread.State: WAITING (parking)
                     at sun.misc.Unsafe.park(Native Method)
                     - parking to wait for  <0x7a380108> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
                     at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186)
                     at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043)
                     at java.util.concurrent.CyclicBarrier.dowait(CyclicBarrier.java:227)
                     at java.util.concurrent.CyclicBarrier.await(CyclicBarrier.java:355)
                     at rollerdemo.TurnstileBarrier.run(RollerBarrier.java:25)
                     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
                     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
                     at java.lang.Thread.run(Thread.java:636)
                
                   Locked ownable synchronizers:
                     - <0x7a382e00> (a java.util.concurrent.ThreadPoolExecutor$Worker)
                
                "pool-1-thread-1" prio=10 tid=0xb4f04800 nid=0x2c8d waiting on condition [0xb50f5000]
                   java.lang.Thread.State: WAITING (parking)
                     at sun.misc.Unsafe.park(Native Method)
                     - parking to wait for  <0x7a387350> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
                     at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186)
                     at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043)
                     at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:386)
                     at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1043)
                     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1103)
                     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
                     at java.lang.Thread.run(Thread.java:636)
                
                   Locked ownable synchronizers:
                     - None
                
                "Low Memory Detector" daemon prio=10 tid=0x08938000 nid=0x2c8b runnable [0x00000000]
                   java.lang.Thread.State: RUNNABLE
                
                   Locked ownable synchronizers:
                     - None
                
                "CompilerThread0" daemon prio=10 tid=0x08936000 nid=0x2c8a waiting on condition [0x00000000]
                   java.lang.Thread.State: RUNNABLE
                
                   Locked ownable synchronizers:
                     - None
                
                "Signal Dispatcher" daemon prio=10 tid=0x08934800 nid=0x2c89 runnable [0x00000000]
                   java.lang.Thread.State: RUNNABLE
                
                   Locked ownable synchronizers:
                     - None
                
                "Finalizer" daemon prio=10 tid=0x0892c800 nid=0x2c88 in Object.wait() [0xb5339000]
                   java.lang.Thread.State: WAITING (on object monitor)
                     at java.lang.Object.wait(Native Method)
                     - waiting on <0x7a383068> (a java.lang.ref.ReferenceQueue$Lock)
                     at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:133)
                     - locked <0x7a383068> (a java.lang.ref.ReferenceQueue$Lock)
                     at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:149)
                     at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:177)
                
                   Locked ownable synchronizers:
                     - None
                
                "Reference Handler" daemon prio=10 tid=0x0892b000 nid=0x2c87 in Object.wait() [0xb538a000]
                   java.lang.Thread.State: WAITING (on object monitor)
                     at java.lang.Object.wait(Native Method)
                     - waiting on <0x7a3830f0> (a java.lang.ref.Reference$Lock)
                     at java.lang.Object.wait(Object.java:502)
                     at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:133)
                     - locked <0x7a3830f0> (a java.lang.ref.Reference$Lock)
                
                   Locked ownable synchronizers:
                     - None
                
                "VM Thread" prio=10 tid=0x08929400 nid=0x2c86 runnable 
                
                "VM Periodic Task Thread" prio=10 tid=0x08943c00 nid=0x2c8c waiting on condition 
                
                JNI global references: 983
                • 5. Re: Strange behaviour with Fixed thread pool
                  jtahlborn
                  if this is the entire stack dump, the biggest question is "where is your main thread"? i see no reference to your main method, which would seem to indicate that your main thread has died. possibly some exception was thrown from you main loop?

                  Edited by: jtahlborn on May 12, 2011 10:48 AM
                  • 6. Re: Strange behaviour with Fixed thread pool
                    861239
                    Thanks Jtahlborn. I did a rerun of the code and took two stack dumps one while the program was running and the second when it blocked. Both of them dont show any main threads. Secondly inside the main method I embedded all the code in a try catch block. It doesnt throw any exception. I can post the two stack dumps if it helps.
                    • 7. Re: Strange behaviour with Fixed thread pool
                      884440
                      Don't know what's with the main thread.
                      But, as per your code, you are eventually bound to get a oome, and a long response time is a precursor to that. Basically, all your worker threads are taking lock on the shared object, and your rate of generating new tasks (read: runnable objects) is very fast: well you have a spinning loop which is just creating objects.

                      By default, fixedThreadPool uses a unbounded blocking queue, i.e., you can dump unlimited number of objects in it (this is what your code is doing). Its overwhelming for the pool, and slows things down. Its not a deadlock, but just over-burdening your existing resources. Either use a bounded blocking queue, and handle when these objects when they overflow, or use cacheThreadPool. More on it later if you are really interested :)
                      • 8. Re: Strange behaviour with Fixed thread pool
                        884820
                        i see it thanks

                        Edited by: user6135449 on Aug 26, 2011 9:08 AM
                        • 9. Re: Strange behaviour with Fixed thread pool
                          796440
                          user6135449 wrote:
                          Any insight will be helpful
                          Did you read the post immediately above yours?