Java Concurrency

The need to write multi-threaded code rarely comes up in my corner of the world. And I know from the admonitions of far better programmers than I that if the need to write multi-threaded code does arise, it is best to tread very, very carefully. But when a Java concurrency problem came up last week, my reaction went beyond being wary. I was unsettled at a gut level. Rather than treading forward with care, I backed away.

My first after-the-fact reaction was, “What the heck was that about?” followed by “That won’t do. That won’t do at all.” It was time to hit the books. I read the chapter on Concurrency in Effective Java (second edition) that I’d previously skipped. And I dug up my old, first edition copy of Doug Lea’s Concurrent Programming in Java. Notes in that book showed that I’d only made it halfway through.

Later, while walking the dog, my mind wandered and I remembered why I’d only made it halfway through Lea’s book. I’d taken it on vacation for airplane reading. Mid vacation, I wasn’t feeling well, so I crawled into bed early, taking the book along. Then, on page 168, the stomach flu hit and I started puking my guts out. Two days that could have been spent on a tropical beach passed most unpleasantly. That was eight years ago. I didn’t open the book again until this weekend.

So I wonder: Could that experience have imprinted a strong, negative association with Java Concurrency? There are precedents. After getting food poisoning from a freeze-dried Mexican meal while backpacking (and then having to hike 10 miles over a mountain pass to get back to the car), the smell of the spice cumin turned my stomach for nearly 15 years. And there was the unfortunate incident that has left me unable to get within smelling distance of Canadian Whiskey without getting queasy. Could the same effect apply to ideas? There are plenty of psychology experiments that show what a few well-timed electric shocks can do to anchor avoidance behaviors. Violent regurgitation at the right moment could probably have the same effect.

Fortunately, negative associations can be overcome. In this case, it means spending some quality time with multi-threaded code, some good music, and maybe a nice cup of tea and some cumin-free cookies.