mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-10-31 02:08:43 +08:00 
			
		
		
		
	【修复】微信支付时,无法保证父线程的 ThreadLocal 传入子线程
This commit is contained in:
		| @@ -7,6 +7,7 @@ import com.google.common.cache.LoadingCache; | |||||||
|  |  | ||||||
| import java.time.Duration; | import java.time.Duration; | ||||||
| import java.util.concurrent.Executor; | import java.util.concurrent.Executor; | ||||||
|  | import java.util.concurrent.ExecutorService; | ||||||
| import java.util.concurrent.Executors; | import java.util.concurrent.Executors; | ||||||
|  |  | ||||||
| /** | /** | ||||||
| @@ -17,8 +18,11 @@ import java.util.concurrent.Executors; | |||||||
| public class CacheUtils { | public class CacheUtils { | ||||||
|  |  | ||||||
|     public static <K, V> LoadingCache<K, V> buildAsyncReloadingCache(Duration duration, CacheLoader<K, V> loader) { |     public static <K, V> LoadingCache<K, V> buildAsyncReloadingCache(Duration duration, CacheLoader<K, V> loader) { | ||||||
|         Executor executor = Executors.newCachedThreadPool(  // TODO 芋艿:可能要思考下,未来要不要做成可配置 |         // 1. 使用 TTL 包装 ExecutorService,实现 ThreadLocal 的透传 | ||||||
|                 TtlExecutors.getDefaultDisableInheritableThreadFactory()); // TTL 保证 ThreadLocal 可以透传 |         // https://github.com/YunaiV/ruoyi-vue-pro/issues/432 | ||||||
|  |         ExecutorService executorService = Executors.newCachedThreadPool(); // TODO 芋艿:可能要思考下,未来要不要做成可配置 | ||||||
|  |         Executor executor = TtlExecutors.getTtlExecutorService(executorService); | ||||||
|  |         // 2. 创建 Guava LoadingCache | ||||||
|         return CacheBuilder.newBuilder() |         return CacheBuilder.newBuilder() | ||||||
|                 // 只阻塞当前数据加载线程,其他线程返回旧值 |                 // 只阻塞当前数据加载线程,其他线程返回旧值 | ||||||
|                 .refreshAfterWrite(duration) |                 .refreshAfterWrite(duration) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 YunaiV
					YunaiV