Skip to content

Commit 3f114a5

Browse files
mknetppkarwasz
authored andcommitted
improve thread-safety
1 parent 86a5516 commit 3f114a5

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

log4j-jul/src/main/java/org/apache/logging/log4j/jul/Log4jBridgeHandler.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,15 @@ public void publish(final LogRecord record) {
179179
}
180180

181181
if (this.installAsLevelPropagator) {
182-
@SuppressWarnings("resource") // no need to close the AutoCloseable ctx here
183-
LoggerContext context = LoggerContext.getContext(false);
184-
context.addConfigurationStartedListener(this);
185-
propagateLogLevels(context.getConfiguration());
186-
// note: java.util.logging.LogManager.addPropertyChangeListener() could also
187-
// be set here, but a call of JUL.readConfiguration() will be done on purpose
188-
this.installAsLevelPropagator = false;
182+
synchronized (this) {
183+
@SuppressWarnings("resource") // no need to close the AutoCloseable ctx here
184+
LoggerContext context = LoggerContext.getContext(false);
185+
context.addConfigurationStartedListener(this);
186+
propagateLogLevels(context.getConfiguration());
187+
// note: java.util.logging.LogManager.addPropertyChangeListener() could also
188+
// be set here, but a call of JUL.readConfiguration() will be done on purpose
189+
this.installAsLevelPropagator = false;
190+
}
189191
}
190192

191193
org.apache.logging.log4j.Logger log4jLogger = getLog4jLogger(record);

0 commit comments

Comments
 (0)