« Dude, where's my document? | Main | Python will assimilate you »

Concurrent Testing and Patterns for Java

Tim Bray:

"I haven't figured out how to do Test-Driven Development of concurrent systems. I know how to write tests that catch an iterator that doesn't iterate and numeric code that loses precision and a million other stupid things that every programmer does. But I don't really know how to write tests that catch simple, bone-headed, obvious errors in concurrent systems."

I'd have to say that in general you can't unit test for this (in Java anyway). However there are means of alleviating matters:

  • Understand the known patterns and idioms. Doug Lea's Java book is a fantastic source of patterns for concurrent OO. It might be the only great programming book that uses Java (great as in Dragon Book great or K&R great).
  • Write less threaded code. Use Doug Lea's stuff, either concurrent.jar or upgrade to 1.5. There's no need to roll your own unless you're doing it for fun.
  • Read everything Brian Goetz has to say about Java threading. Smart guy, writes well.
  • Matt Albrecht has a nice utility in grobo utils: MultiThreadedTestRunner. Good for heightening concurrency in tests and thus flushing out bugs.
  • Doug Schmidt's POSA2 book is a good source of patterns. It's a bit turgid in spots, but worth it for the Reactor and Half-Sync/Half-Async patterns alone.
  • Use less threads. Events, events, events - especially for io.
  • For valour:

You could of course go the route of using alternative languages.


August 7, 2004 05:25 PM

Comments

Trackback Pings

TrackBack URL for this entry:
http://www.dehora.net/mt/mt-tb.cgi/1369