Commit d30700d06003ed72dfed27b547ad2544f088c2ee
1 parent
1f35ef59
【修复】微信支付时,无法保证父线程的 ThreadLocal 传入子线程
Showing
1 changed file
with
6 additions
and
2 deletions
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/cache/CacheUtils.java
| @@ -7,6 +7,7 @@ import com.google.common.cache.LoadingCache; | @@ -7,6 +7,7 @@ import com.google.common.cache.LoadingCache; | ||
| 7 | 7 | ||
| 8 | import java.time.Duration; | 8 | import java.time.Duration; |
| 9 | import java.util.concurrent.Executor; | 9 | import java.util.concurrent.Executor; |
| 10 | +import java.util.concurrent.ExecutorService; | ||
| 10 | import java.util.concurrent.Executors; | 11 | import java.util.concurrent.Executors; |
| 11 | 12 | ||
| 12 | /** | 13 | /** |
| @@ -17,8 +18,11 @@ import java.util.concurrent.Executors; | @@ -17,8 +18,11 @@ import java.util.concurrent.Executors; | ||
| 17 | public class CacheUtils { | 18 | public class CacheUtils { |
| 18 | 19 | ||
| 19 | public static <K, V> LoadingCache<K, V> buildAsyncReloadingCache(Duration duration, CacheLoader<K, V> loader) { | 20 | public static <K, V> LoadingCache<K, V> buildAsyncReloadingCache(Duration duration, CacheLoader<K, V> loader) { |
| 20 | - Executor executor = Executors.newCachedThreadPool( // TODO 芋艿:可能要思考下,未来要不要做成可配置 | ||
| 21 | - TtlExecutors.getDefaultDisableInheritableThreadFactory()); // TTL 保证 ThreadLocal 可以透传 | 21 | + // 1. 使用 TTL 包装 ExecutorService,实现 ThreadLocal 的透传 |
| 22 | + // https://github.com/YunaiV/ruoyi-vue-pro/issues/432 | ||
| 23 | + ExecutorService executorService = Executors.newCachedThreadPool(); // TODO 芋艿:可能要思考下,未来要不要做成可配置 | ||
| 24 | + Executor executor = TtlExecutors.getTtlExecutorService(executorService); | ||
| 25 | + // 2. 创建 Guava LoadingCache | ||
| 22 | return CacheBuilder.newBuilder() | 26 | return CacheBuilder.newBuilder() |
| 23 | // 只阻塞当前数据加载线程,其他线程返回旧值 | 27 | // 只阻塞当前数据加载线程,其他线程返回旧值 |
| 24 | .refreshAfterWrite(duration) | 28 | .refreshAfterWrite(duration) |