File tree Expand file tree Collapse file tree
src/main/java/site/praytogether/pray_together/config Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ public Executor notificationExecutor() {
1717 executor .setQueueCapacity (100 );
1818 executor .setMaxPoolSize (10 );
1919 executor .setThreadNamePrefix ("notification-" );
20+ executor .setTaskDecorator (new MdcTaskDecorator ());
2021 executor .setWaitForTasksToCompleteOnShutdown (true );
2122 executor .setAwaitTerminationSeconds (30 );
2223 executor .initialize ();
@@ -30,6 +31,7 @@ public Executor emailExecutor() {
3031 executor .setQueueCapacity (50 );
3132 executor .setMaxPoolSize (10 );
3233 executor .setThreadNamePrefix ("email-" );
34+ executor .setTaskDecorator (new MdcTaskDecorator ());
3335 executor .setWaitForTasksToCompleteOnShutdown (true );
3436 executor .setAwaitTerminationSeconds (60 );
3537 executor .initialize ();
Original file line number Diff line number Diff line change 1+ package site .praytogether .pray_together .config ;
2+
3+ import java .util .Map ;
4+ import org .slf4j .MDC ;
5+ import org .springframework .core .task .TaskDecorator ;
6+ import org .springframework .lang .NonNull ;
7+
8+ public class MdcTaskDecorator implements TaskDecorator {
9+
10+ @ Override
11+ @ NonNull
12+ public Runnable decorate (@ NonNull Runnable runnable ) {
13+ Map <String , String > contextMap = MDC .getCopyOfContextMap ();
14+ return () -> {
15+ if (contextMap != null ) {
16+ MDC .setContextMap (contextMap );
17+ }
18+ try {
19+ runnable .run ();
20+ } finally {
21+ MDC .clear ();
22+ }
23+ };
24+ }
25+ }
You can’t perform that action at this time.
0 commit comments