Library with debugging tools for concurrent code?

View: New views
1 Messages — Rating Filter:   Alert me  

Library with debugging tools for concurrent code?

by Christian Vest Hansen :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi.

I'm finding that the current java.util.concurrent APIs a good for
writing unit tests that verify correct behavior of the multithreaded
code that I write - especially the CountDownLatch and Atomic* classes.
However, a couple of things are hard. One of those things is finding
the cause when things go wrong.

Here's a story: I was working on a unit test yesterday. I needed to
verify that some task scheduler executed the jobs submitted to it, and
I did this by submitting a job that would count up an AtomicInteger
and open a latch. The opened latch would let the junit thread proceed
to assert against the value of the AtomicInteger, expecting it to be
1. However, the count was *occasionally* 2. Looking through my
production code, I found no way for this to happen, yet it did. I
needed to figure out who was touching my counter, so I created a
ThreadMarkingAtomicInteger (bad name) that would record the thread,
new value and a stack trace, in a ConcurrentLinkedQueue on every
mutation. From this data, I could see that the mutations were coming
from threads from two different schedulers. The scheduler was
reconstructed prior to every unit test run, so the only logical
conclusion was, that I had a race between resetting it after one test
and reusing it in the next. This also explained why the bug only
surfaced in the second of two tests.

The TMAI was helpful, but a slight bother because my existing test
code was using AtomicIntegers which I could not extend because all of
the interesting methods are final.

The thing I wonder is, would it make sense with a library of parts
that can drop-in replace existing j.u.c parts and help with debugging?
This could be synchronizers that throws (or callbacks) when N parses
some threshold (no one must ever wait on this lock; no more than 3
threads are allowed to wait on this latch) or stuff like TMAI that
keep record of their use.


--
Venlig hilsen / Kind regards,
Christian Vest Hansen.
_______________________________________________
Concurrency-interest mailing list
Concurrency-interest@...
http://cs.oswego.edu/mailman/listinfo/concurrency-interest