buzzco.org

Drunk and Famous

buzzco.org header image 2

Java 1.4.2 and I are not speaking.

June 19th, 2007 · No Comments

I am not a developer. I am a tinkerer

I write small stuff. At work, I have been tricked into doing some java development. Its kinda fun, getting make into the grind. But there are some things that I have be finding ( or refinding; its been a long time since I wrote usable java.)

Anyway, I was implementing the singleton design pattern. You may have heard of this. I have done it many times in many different languages, but never really had to make it enterprise ready. So I started to look into it making sure I understood the voodoo.

First I normally use something like double-check locking.
Well I shouldn’t. I see lots of articles on the web that use this. Well it really doesn’t work. Me not being the best java programmer didn’t know that. But then I found this.

So instead, I am using something like this.
The cause for double-check locking to fail for use on singletons is complicated, and was hotly debated before the Java Memory Map was revised in 5.0.

I am really glad I didn’t just go with the double-check locking. I have a feeling that the rare race condition that is exposed would be really hard to detect.

							

Tags: Uncategorized

0 responses so far ↓

  • There are no comments yet...Kick things off by filling out the form below.

Leave a Comment