|  | @ -1,5 +1,6 @@ | 
			
		
	
		
		
			
				
					|  |  | package com.epmet.commons.tools.config; |  |  | package com.epmet.commons.tools.config; | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  | import com.alibaba.ttl.TtlRunnable; | 
			
		
	
		
		
			
				
					|  |  | import com.alibaba.ttl.threadpool.TtlExecutors; |  |  | import com.alibaba.ttl.threadpool.TtlExecutors; | 
			
		
	
		
		
			
				
					|  |  | import org.slf4j.MDC; |  |  | import org.slf4j.MDC; | 
			
		
	
		
		
			
				
					|  |  | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |  |  | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | 
			
		
	
	
		
		
			
				
					|  | @ -64,8 +65,9 @@ public class AsyncConfig { | 
			
		
	
		
		
			
				
					|  |  |         executor.setKeepAliveSeconds(keepAliveSeconds); |  |  |         executor.setKeepAliveSeconds(keepAliveSeconds); | 
			
		
	
		
		
			
				
					|  |  |         // 设置装饰器,使用MDC将runnable进行装饰,实现日志上下文传递到子线程
 |  |  |         // 设置装饰器,使用MDC将runnable进行装饰,实现日志上下文传递到子线程
 | 
			
		
	
		
		
			
				
					|  |  |         executor.setTaskDecorator((Runnable r) -> { |  |  |         executor.setTaskDecorator((Runnable r) -> { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             // 1.mdc包装,日志追踪
 | 
			
		
	
		
		
			
				
					|  |  |             Map<String, String> copyOfContextMap = MDC.getCopyOfContextMap(); |  |  |             Map<String, String> copyOfContextMap = MDC.getCopyOfContextMap(); | 
			
		
	
		
		
			
				
					
					|  |  |             return () -> { |  |  |             Runnable rr = () -> { | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |                 try { |  |  |                 try { | 
			
		
	
		
		
			
				
					|  |  |                     if (copyOfContextMap != null && copyOfContextMap.size() > 0) { |  |  |                     if (copyOfContextMap != null && copyOfContextMap.size() > 0) { | 
			
		
	
		
		
			
				
					|  |  |                         MDC.setContextMap(copyOfContextMap); |  |  |                         MDC.setContextMap(copyOfContextMap); | 
			
		
	
	
		
		
			
				
					|  | @ -75,6 +77,9 @@ public class AsyncConfig { | 
			
		
	
		
		
			
				
					|  |  |                     MDC.clear(); |  |  |                     MDC.clear(); | 
			
		
	
		
		
			
				
					|  |  |                 } |  |  |                 } | 
			
		
	
		
		
			
				
					|  |  |             }; |  |  |             }; | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             // 2.ttl包装,异步线程上下文透传
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             return TtlRunnable.get(rr); | 
			
		
	
		
		
			
				
					|  |  |         }); |  |  |         }); | 
			
		
	
		
		
			
				
					|  |  |         executor.initialize(); |  |  |         executor.initialize(); | 
			
		
	
		
		
			
				
					|  |  |         return executor; |  |  |         return executor; | 
			
		
	
	
		
		
			
				
					|  | 
 |