parent
							
								
									614d3fc273
								
							
						
					
					
						commit
						d6bd37bcba
					
				
				 2 changed files with 45 additions and 0 deletions
			
			
		| @ -0,0 +1,27 @@ | |||||||
|  | package org.anyin.gitee.shiro.base; | ||||||
|  | 
 | ||||||
|  | import org.slf4j.MDC; | ||||||
|  | 
 | ||||||
|  | import java.util.concurrent.Executor; | ||||||
|  | 
 | ||||||
|  | public class MdcExecutor implements Executor { | ||||||
|  | 
 | ||||||
|  |     private Executor executor; | ||||||
|  | 
 | ||||||
|  |     public MdcExecutor(Executor executor) { | ||||||
|  |         this.executor = executor; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public void execute(Runnable command) { | ||||||
|  |         final String requestId = MDC.get("REQUEST_ID"); | ||||||
|  |         executor.execute(() -> { | ||||||
|  |             MDC.put("REQUEST_ID", requestId); | ||||||
|  |             try { | ||||||
|  |                 command.run(); | ||||||
|  |             } finally { | ||||||
|  |                 MDC.remove("REQUEST_ID"); | ||||||
|  |             } | ||||||
|  |         }); | ||||||
|  |     } | ||||||
|  | } | ||||||
					Loading…
					
					
				
		Reference in new issue
	
	 陈景阳
						陈景阳