Alex Miller aka Pure Danger Tech has a great entry on most common concurrency bugs.
the timing is perfect – this very thing bit me today. long story short, an old app, previously perceived to be multi-threaded, was recently converted to actually be multi-threaded, and then, once traffic ramped up a bit, exhibited peculiar behavior when perfectly good dates could not be parsed. thank god it blew up, as opposed to quietly corrupting the data.
so something as innocent-looking as
private static final SimpleDateFormat
declaration was the culprit:
java.text.DateFormat
is not thread-safe.
luckily, it is easy enough to spot and reproduce (threadPoolSize
and
invocationCount
in TestNG simplify it even
further).
a pessimist would heave a mighty sigh, once again swear on the copy of
JCIP to
find and root out every frivolous static
out there with the help of
FindBugs
or a simple regex.
meanwhile, there is joda-time and a promise of jsr310
but of course this whole experience still leaves you feeling cheated and dirty – why, god, why?! something so function-like and stateless in nature insists on stowing things away.