jayway/awaitility — pull request #10 by Turbo87 (2014-10-06 09:07:04+00:00)
Title: Automatic Deadlock Detection

This code will check for deadlocked threads if a ConditionTimeoutException is thrown and attaches the thread information to the exception if something is detected.

The included `DeadlockDetectionTest` will cause the following exception:

~~~
com.jayway.awaitility.core.ConditionTimeoutException: com.jayway.awaitility.core.ConditionFactory.untilAtomic Callable expected ( or ) but was within 1 seconds.
at com.jayway.awaitility.core.ConditionAwaiter.await(ConditionAwaiter.java:96)
at com.jayway.awaitility.core.AbstractHamcrestCondition.await(AbstractHamcrestCondition.java:136)
at com.jayway.awaitility.core.ConditionFactory.until(ConditionFactory.java:590)
at com.jayway.awaitility.core.ConditionFactory.untilAtomic(ConditionFactory.java:505)
at com.jayway.awaitility.core.ConditionFactory.untilTrue(ConditionFactory.java:519)
at com.jayway.awaitility.DeadlockDetectionTest.atomicBooleanExample(DeadlockDetectionTest.java:55)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.FailOnTimeout$StatementThread.run(FailOnTimeout.java:62)
Caused by: com.jayway.awaitility.core.DeadlockException: Deadlocked threads detected:

"Thread-2" Id=11 BLOCKED on java.lang.Object@72fb24c owned by "Thread-1" Id=10
at com.jayway.awaitility.DeadlockDetectionTest$2.run(DeadlockDetectionTest.java:45)
- blocked on java.lang.Object@72fb24c
- locked java.lang.Object@6273e11a

"Thread-1" Id=10 BLOCKED on java.lang.Object@6273e11a owned by "Thread-2" Id=11
at com.jayway.awaitility.DeadlockDetectionTest$1.run(DeadlockDetectionTest.java:31)
- blocked on java.lang.Object@6273e11a
- locked java.lang.Object@72fb24c

at com.jayway.awaitility.core.ConditionAwaiter.await(ConditionAwaiter.java:101)
... 14 more
~~~