2

Say we have two methods that are called asynchronously. methodA() is called a few thousand times, and somewhere down the line methodA() calls methodB(). The caller of methodB() needs the result using Future/AsyncResult before continuing.

@Asynchronous methodA()

@Asynchronous methodB()

The problem is that they use the same thread pool, and once all of the methodA() calls are queued up, there are no more threads available for methodB(). Thus all the methodA() calls that are running are waiting for methodB() and we have a deadlock.

Is there anyway around this? Shouldn't there be a way to specify which thread pool to use in an @Asynchronous method? We are using glassfish 3.1.2.2.

Stack trace has a lot of threads like this:

   java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for  <0x00000007e1a4b010> (a java.util.concurrent.FutureTask$Sync)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:156)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:811)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireSharedInterruptibly(AbstractQueuedSynchronizer.java:969)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly(AbstractQueuedSynchronizer.java:1281)
at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:218)
at java.util.concurrent.FutureTask.get(FutureTask.java:83)
at com.sun.ejb.containers.EjbFutureTask.get(EjbFutureTask.java:106)
JoshP
  • 355
  • 1
  • 9
  • 1
    Have you considered using JMS with MDB's for this instead? – Perception Jan 15 '13 at 22:30
  • The response to this [question](http://stackoverflow.com/questions/13932083/jboss-java-ee-container-and-an-executorservice) said that this is a discussed issue with the EJB spec, but I haven't been able to find the discussion yet. Did you give up and use MDBs? – Kent Watsen Mar 20 '13 at 23:48
  • 1
    yup gave up and used MDBs – JoshP Apr 05 '13 at 19:11

0 Answers0