* enqueue a message into the queue which then should be returned to the first thread.
* wrong synchronization led to a deadlock.
*/
public void testDeadlock() throws Exception
{
final AnyMessage mesg = new AnyMessage();
final AtomicBoolean received = new AtomicBoolean(false);
final AtomicBoolean delivered = new AtomicBoolean(false);
final CountDownLatch threadsDone = new CountDownLatch(1);
final CountDownLatch getPutOrder = new CountDownLatch(1);
final AtomicReference getException = new AtomicReference(null);
final AtomicReference putException = new AtomicReference(null);
final CyclicBarrier barrier = new CyclicBarrier(2, new Runnable()
{
public void run()
{
threadsDone.countDown();
}
});
Runnable getCommand = new Runnable()
{
public void run()
{
try
{
synchronized (lock_)
{
getPutOrder.countDown();
objectUnderTest_.getMessageBlocking();
}
received.set(true);
} catch (Exception e)
{
getException.set(e);
}
finally
{
try
{
barrier.await();
} catch (InterruptedException e)
{
// ignored
} catch (BrokenBarrierException e)
{
// should not happen
e.printStackTrace();
}
}
}
};
Runnable putCommand = new Runnable()
{
public void run()
{
try
{
getPutOrder.await();
objectUnderTest_.enqeue(mesg.getHandle());
delivered.set(true);
} catch (Exception e)
{
putException.set(e);