北京住总第三开发建设有限公司网站,im聊天软件开发,东莞需要做推广的公司,网站商城微信支付将父类的 threadLocal 的数据 在线程池时#xff0c;可以转给子线程使用。
Async 的使用。
第一步在启动服务加上 EnableAsync 注解。
EnableAsync
public class NetCoreApplication {... ...
}第二步#xff1a;导入阿里 线程工具类dependencygroupIdcom.a…将父类的 threadLocal 的数据 在线程池时可以转给子线程使用。
Async 的使用。
第一步在启动服务加上 EnableAsync 注解。
EnableAsync
public class NetCoreApplication {... ...
}第二步导入阿里 线程工具类dependencygroupIdcom.alibaba/groupIdartifactIdtransmittable-thread-local/artifactIdversion2.14.5/version/dependency第三步增加 线程池。提供给 Async 用。
ExecutorService executor ThreadUtil.newExecutor(10, 200);
ExecutorService ttlExecutor TtlExecutors.getTtlExecutorService(executor);
return ttlExecutor;
Component
public class MyThreadPool {/*** 不方便使用注解时调用该方法可以执行异步操作。*/Asyncpublic void exe(Runnable runner) {runner.run();}/*** TtlExecutors 这个线程池很重要可以让子线程继承父线程的threadLocal数据* return*/Beanpublic Executor taskExecutor() {ExecutorService executor ThreadUtil.newExecutor(10, 200);ExecutorService ttlExecutor TtlExecutors.getTtlExecutorService(executor);return ttlExecutor;}}