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)