commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Julien Aymé" <>
Subject Multi-threading unit test
Date Tue, 05 Jun 2007 09:39:34 GMT
Hi everybody,

I am searching for a way to do some JUnit tests which would trigger a
ConcurrentModificationException on some collections (see
For that, the naive way is to create some threads and start them at
the same time.
With that approach, the problem is that the exception is triggered
into one of the children threads, and not in the main thread (the
JUnit thread).

I have listed some ways to gather the exceptions that would be thrown
in the children threads into the main thread:
    - 1. The simplest solution (to my mind). Create a
UnhandledExceptionHandler which would store the exceptions of the
children threads, in a list for example, keep a reference to that
handler in the main thread, wait to the children threads to finish
(with Thread#join()), then if the list of exceptions is not empty,
throw them*.
    - 2. Create a specialized thread which would overwrite #run() by
catching any exception and keeping a reference to it, and a
specialized join() method which would regroup all the exceptions, and
throw them* if any.

*I wonder what would be the advantages/disadvantages of an Exception
which would contains multiple exceptions, whose printstacktrace method
would print all the stacktraces of the contained exception.

I'd be glad to have any comments/suggestions, and I'd like to know in
which project should I contribute to these classes, as I intend to
implement both of ways, and I think that many projects in commons
would benefit from these.


PS: If there is already some projects in commons which do the same,
let me know :-)

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message