Michael In case you didn't know: The double-checked locking pattern originally proposed by Douglas C. Schmidt is proven inherently unsafe in Java.
See http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html. -- Thomas | -----Original Message----- | From: Michael Mason [mailto:[EMAIL PROTECTED]] | Sent: 12 October 2001 15:04 | To: 'LOG4J Users Mailing List' | Subject: RE: PropertyConfigurator.configure method in J2EE | | | > import org.apache.tools.log4j.Category; | > | > public class LoggerFactory { | > | > private static boolean configured = false; | > | > private static void configure() { | > if (!configured) { | > /*** Place all your configuration stuff here. ***/ | > configured = true; | > } | > } | > | > public static Category getInstance(Class c) { | > configure(); | > return Category.getInstance(c); | > } | > | > public static Category getInstance(String s) { | > configure(); | > return Category.getInstance(s); | > } | > | > } | | This isn't thread-safe, because if two threads call getInstance() | at the same time, your configure code could run twice. A slightly | better solution would be to use synchronized to make sure it's | thread safe. This is technically against the J2EE spec. Here it | is anyway: | | private static void configure() { | if(!configured) { | synchronized(LoggerFactory.class) { | if(!configured) { | /** Do config */ | configured = true; | } | } | } | } | | Note the double-check of the configured boolean. | | Having said all that, running config code twice probably isn't the | end of the world, and might not happen very often. | | Regards, | Mike. | | --------------------------------------------------------------------- | To unsubscribe, e-mail: [EMAIL PROTECTED] | For additional commands, e-mail: [EMAIL PROTECTED] | | ************************************************************************* Copyright ERA Technology Ltd. 2001. (www.era.co.uk). All rights reserved. Confidential. No liability whatsoever is accepted for any loss or damage suffered as a result of accessing this message or any attachments. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]