commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Kitching <skitch...@apache.org>
Subject Re: [logging] Log4JLogger thread safety issue
Date Thu, 19 Jan 2006 21:56:09 GMT
On Thu, 2006-01-19 at 20:04 +0000, robert burrell donkin wrote:

> i was wondering whether a logger could be partially constructed and if
> so what the likely effect would be (thread A enters getLogger() and
> starts the construction of the logger but is not finished before thread
> B enters the method and finds logger has been assigned (so not null) but
> not completed constructed.) i'm unsure whether this scenario is allowed
> by the java language and virtual machine specifications. a few similarly
> unintuitive ones are.

For the code
   logger = Logger.getLogger(name)
the assignment won't happen until the object returned by
Logger.getLogger is 100% complete. There's no way to get access to a
partially-initialised object here. 

There is a window in which two threads can both see logger==null, but as
described in the earlier email that causes no problems. The first thread
returns a reference to object X which it assigns to logger, then the
second thread returns a reference to object X which it uses to overwrite
the previous one. No problem.

Regards,

Simon


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message