[ 
https://issues.apache.org/jira/browse/LOG4J2-169?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13591564#comment-13591564
 ] 

Ralph Goers commented on LOG4J2-169:
------------------------------------

The article you reference is very old. Take a look at 
http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html and then 
search for "volatile" (this is just the first article Google gave me when I 
searched - there are others).  You will notice that in the code fragment I 
posted above the factories variable is declared volatile. Noel left it out in 
his example because he was simply fixing the mistake I made of not checking the 
variable again. 

The semantics of volatile changed in Java 5 such that it provides some of the 
same guarantees you get with synchronizing access to a variable. Log4j2 takes 
advantage of this during reconfiguration to avoid having to synchronize access 
to the configuration. See 
http://www.javamex.com/tutorials/synchronization_volatile_java_5.shtml for a 
reasonable, if simple, explanation. There are some other things that can happen 
with non-volatile variables or even volatile variables prior to java 5 that 
won't any more due to the memory guarantees.

In any case, DCL does work if the variable being checked is declared volatile 
or is an element of a ConcurrentHashMap, or the like, which provide similar 
guarantees.
                
> LogManager.getLogger doesn't work
> ---------------------------------
>
>                 Key: LOG4J2-169
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-169
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 2.0-beta4
>            Reporter: Jed Wesley-Smith
>            Priority: Critical
>              Labels: thread-safety
>
> We randomly get the following:
> java.util.ConcurrentModificationException
>       at 
> org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:377)
>       at 
> org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:361)
>       at 
> org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:266)
>       at 
> org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:134)
>       at 
> org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:75)
>       at 
> org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:30)
>       at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:165)
>       at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:174)
>       at …
> factories is defined as:
>     private static List<ConfigurationFactory> factories = new 
> ArrayList<ConfigurationFactory>();
> The simple fix is to use a java.util.concurrent.CopyOnWriteArrayList:
>     private static final List<ConfigurationFactory> factories = new 
> CopyOnWriteArrayList<ConfigurationFactory>();
> https://svn.apache.org/repos/asf/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to