Skip to content

Instantly share code, notes, and snippets.

@umit
Last active March 6, 2021 10:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save umit/8f88a87aa96567fc73a3b20de4a3d9af to your computer and use it in GitHub Desktop.
Save umit/8f88a87aa96567fc73a3b20de4a3d9af to your computer and use it in GitHub Desktop.
MDC integration with ThreadPoolTaskExecutor
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