Last active
March 6, 2021 10:53
-
-
Save umit/8f88a87aa96567fc73a3b20de4a3d9af to your computer and use it in GitHub Desktop.
MDC integration with ThreadPoolTaskExecutor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public TaskExecutor taskExecutor() { | |
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor(); | |
taskExecutor.setCorePoolSize(10); | |
taskExecutor.setMaxPoolSize(25); | |
taskExecutor.setQueueCapacity(100); | |
taskExecutor.setTaskDecorator(runnable -> { | |
Map<String, String> contextMap = MDC.getCopyOfContextMap(); | |
return () -> { | |
try { | |
MDC.setContextMap(contextMap); | |
runnable.run(); | |
} finally { | |
MDC.clear(); | |
} | |
}; | |
}); | |
return taskExecutor; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment