I think I read somewhere (javaworld?) that the double-checking pattern for object locking is unsafe in Java. I can't remember the details. It's something related to the way Java compiler optimising the generate code by swapping statements silently.


At 01:52 pm 15-08-2001 +0200, you wrote:

You can either use JNDI connection pool. Or you can read the data in an
action and cache them then. I'd use the double checked singleton pattern:

Thing getThing() {
    if (null == this.thing) {
        synchronized(this) {
            if (null == this.thing) {
                // read the thing form the database
            }
        }
    }
    return thing;
}

--
John Yu                       Scioworks Technologies
e: [EMAIL PROTECTED]         w: +(65) 873 5989
w: http://www.scioworks.com  m: +(65) 9782 9610

Reply via email to