Skip to content

Commit

Permalink
+ better worker context switch
Browse files Browse the repository at this point in the history
  • Loading branch information
q3769 committed Apr 26, 2024
1 parent e1d2a6b commit da046a3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

<groupId>io.github.elf4j</groupId>
<artifactId>elf4j-engine</artifactId>
<version>15.2.3</version>
<version>15.2.4</version>
<packaging>jar</packaging>
<name>elf4j-engine</name>
<description>A stand-alone Java log engine implementing the ELF4J (Easy Logging Facade for Java) API</description>
Expand Down
22 changes: 10 additions & 12 deletions src/main/java/elf4j/engine/service/writer/GroupWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,17 @@ private static List<LogWriterType> getLogWriterTypes(@NonNull LogServiceConfigur
.collect(Collectors.toList());
}

private static Runnable withMdcContext(Runnable task) {
private static @NonNull Runnable withMdcContext(Runnable task) {
Map<String, String> callerContext = MDC.getCopyOfContextMap();
return (callerContext == null || callerContext.isEmpty())
? task
: () -> {
Map<String, String> workerContext = replaceContextWith(callerContext);
MDC.setContextMap(callerContext);
try {
task.run();
} finally {
MDC.setContextMap(workerContext);
}
};
return () -> {
Map<String, String> workerContext = replaceContextWith(callerContext);
MDC.setContextMap(callerContext);
try {
task.run();
} finally {
MDC.setContextMap(workerContext);
}
};
}

private static Map<String, String> replaceContextWith(Map<String, String> targetContext) {
Expand Down

0 comments on commit da046a3

Please sign in to comment.