KentBeck/junit — pull request #528 by Tibor17 (2012-10-15 22:18:08+00:00)
Title: fixed and improved Java Concurrency in RunNotifier

I found several Java Concurrency issues in JUnit for parallel testing.
RunNotifier is the first issue.

Problems:

+ synchronizedList(new ArrayList()) is an old construction which has a problem with the new Java Memory Model since Java 1.5. The constructor ArrayList() does not have thread-safe context.
There are other modern totally thread-safe collections like CopyOnWriteArrayList, etc.
+ all the operations, except for addListener() removeListener() and addFirstListener(), might be non-blocking -still making the progress because only reading the content of fListeners;
+ the operations addListener() removeListener() and addFirstListener() modify the content of fListeners and therefore must be blocking.
+ Reentrant locks use to be faster than traversing across all application threads via synchronized.

Reason to use locks in run():
We must not use iterator snapshot via CopyOnWriteArrayList in run() without synchronization, because the fireTestFailures() must operate on yet non-removed listeners. Therefore run() must use mutual exclusion with addListener() removeListener() and addFirstListener().