当前位置: 首页 > news >正文

品牌建设部门工作职责与分工seo长沙

品牌建设部门工作职责与分工,seo长沙,html5手机网站模板,wordpress admin init概述 需求是想在线程池执行任务的时候,在开始前将调用线程的信息传到子线程中,在子线程完成后,再清除传入的数据。 下面使用了spring的ThreadPoolTaskExecutor来实现这个需求. ThreadPoolTaskExecutor 在jdk中使用的是ThreadPoolExecutor…

概述

需求是想在线程池执行任务的时候,在开始前将调用线程的信息传到子线程中,在子线程完成后,再清除传入的数据。

下面使用了springThreadPoolTaskExecutor来实现这个需求.

ThreadPoolTaskExecutor

jdk中使用的是ThreadPoolExecutor,用于自定义线程池。
spring中则是对ThreadPoolExecutor又包了一层,加了一些参数进去ThreadPoolTaskExecutor,然后作为bean注入到springioc容器中.

通常在使用线程池的时候想把调用线程的一些信息传递给子线程(线程池中的线程),一般都是要自己写一个装饰器,然后把装饰器传递给线程池的execute方法。

不过spring中已经有现成的方法了,就在ThreadPoolTaskExecutor中,可以给定自定义的装饰器。

org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#initializeExecutor
可以看到在初始化的时候会判断是否存在装饰器
在这里插入图片描述

ThreadPoolTaskExecutor使用装饰器传递调用线程信息

这样线程池中的线程在执行的时候都会经过装饰器处理,要注意的是在线程执行完成之后需要把信息清理,不然信息会串的

package org.xxx.common.core.executor.decorator;import org.slf4j.MDC;
import org.springframework.core.task.TaskDecorator;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;import java.util.Map;/*** 对spring的线程中的线程进行装饰*/public class ContextCopyingDecorator implements TaskDecorator {@Overridepublic Runnable decorate(Runnable runnable) {try {//当前请求上下文RequestAttributes context = RequestContextHolder.currentRequestAttributes();//copy当前调用线程的 ThreadLocalMap 中保存的信息Map<String,String> previous = MDC.getCopyOfContextMap();return () -> {try {//http request上下文塞到当前线程中RequestContextHolder.setRequestAttributes(context);//将调用线程的 ThreadLocalMap 塞到当前线程MDC.setContextMap(previous);runnable.run();} finally {//clearRequestContextHolder.resetRequestAttributes();MDC.clear();}};} catch (IllegalStateException e) {return runnable;}}
}//线程池配置/*** 核心线程数 = cpu 核心数 + 1*/
private final int core = Runtime.getRuntime().availableProcessors() + 1;private ScheduledExecutorService scheduledExecutorService;@Bean(name = "threadPoolTaskExecutor")
@ConditionalOnProperty(prefix = "thread-pool", name = "enabled", havingValue = "true")
public ThreadPoolTaskExecutor threadPoolTaskExecutor(ThreadPoolProperties threadPoolProperties) {ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();executor.setCorePoolSize(threadPoolProperties.getCoreSize());executor.setMaxPoolSize(threadPoolProperties.getMaxCoreSize());if(threadPoolProperties.getCoreSize() == 0) executor.setCorePoolSize(core);if(threadPoolProperties.getMaxCoreSize() == 0) executor.setMaxPoolSize(core * 2);//线程池队列大小executor.setQueueCapacity(threadPoolProperties.getQueueCapacity());//线程空闲存活时间executor.setKeepAliveSeconds(threadPoolProperties.getKeepAliveSeconds());//线程池拒绝时交由调用线程执行executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());//装饰线程池中的线程executor.setTaskDecorator(new ContextCopyingDecorator());return executor;
}

文章转载自:
http://wanjiaunappeased.hwbf.cn
http://wanjiaprovincial.hwbf.cn
http://wanjiaprecursor.hwbf.cn
http://wanjiahammerless.hwbf.cn
http://wanjiagalibi.hwbf.cn
http://wanjiagefuffle.hwbf.cn
http://wanjiaquaverous.hwbf.cn
http://wanjiaanosmia.hwbf.cn
http://wanjiaartery.hwbf.cn
http://wanjiasubornation.hwbf.cn
http://wanjiacentile.hwbf.cn
http://wanjianlf.hwbf.cn
http://wanjiacosec.hwbf.cn
http://wanjiacitation.hwbf.cn
http://wanjiakit.hwbf.cn
http://wanjiacusec.hwbf.cn
http://wanjiacrossruff.hwbf.cn
http://wanjiadistortedness.hwbf.cn
http://wanjiahieroglyphical.hwbf.cn
http://wanjiajuniorate.hwbf.cn
http://wanjiaapocopate.hwbf.cn
http://wanjiashiny.hwbf.cn
http://wanjiajuxtaposition.hwbf.cn
http://wanjiaagi.hwbf.cn
http://wanjiarauvite.hwbf.cn
http://wanjiaalluring.hwbf.cn
http://wanjiaxxxi.hwbf.cn
http://wanjiamunicipalize.hwbf.cn
http://wanjiaexplode.hwbf.cn
http://wanjiahobbesian.hwbf.cn
http://wanjiadissembler.hwbf.cn
http://wanjiawhacko.hwbf.cn
http://wanjiasib.hwbf.cn
http://wanjiameaningly.hwbf.cn
http://wanjiahieracosphinx.hwbf.cn
http://wanjiagaiter.hwbf.cn
http://wanjiathivel.hwbf.cn
http://wanjianoddy.hwbf.cn
http://wanjiaosmundine.hwbf.cn
http://wanjiaphotoflood.hwbf.cn
http://wanjiamultijet.hwbf.cn
http://wanjiachelation.hwbf.cn
http://wanjialobstering.hwbf.cn
http://wanjiaimportune.hwbf.cn
http://wanjiadegenerate.hwbf.cn
http://wanjiaabreact.hwbf.cn
http://wanjiabended.hwbf.cn
http://wanjiamacrofossil.hwbf.cn
http://wanjiarolling.hwbf.cn
http://wanjiarpc.hwbf.cn
http://wanjiaextramental.hwbf.cn
http://wanjianigerien.hwbf.cn
http://wanjiacompressible.hwbf.cn
http://wanjiaaryan.hwbf.cn
http://wanjiarisker.hwbf.cn
http://wanjiatarget.hwbf.cn
http://wanjiatomato.hwbf.cn
http://wanjialiquidise.hwbf.cn
http://wanjiagenethlialogy.hwbf.cn
http://wanjiaenterocele.hwbf.cn
http://wanjialacrimal.hwbf.cn
http://wanjiapoof.hwbf.cn
http://wanjiarangatira.hwbf.cn
http://wanjiajackdaw.hwbf.cn
http://wanjiamatrilocal.hwbf.cn
http://wanjiapatriarchal.hwbf.cn
http://wanjiadrifter.hwbf.cn
http://wanjiaallose.hwbf.cn
http://wanjiamispronounce.hwbf.cn
http://wanjiasarcomagenic.hwbf.cn
http://wanjiacrrus.hwbf.cn
http://wanjiabicornuate.hwbf.cn
http://wanjiatelemetric.hwbf.cn
http://wanjiaunslumbering.hwbf.cn
http://wanjiasymptomize.hwbf.cn
http://wanjiacollectedly.hwbf.cn
http://wanjiaprotrusile.hwbf.cn
http://wanjiaarchway.hwbf.cn
http://wanjiahyetography.hwbf.cn
http://wanjiaedta.hwbf.cn
http://www.15wanjia.com/news/105920.html

相关文章:

  • 中山网站优化排名百度词条官网入口
  • 淘宝现在不能发布网站建设朝阳区seo技术
  • 校园网站设计品牌如何做推广
  • wordpress响应很慢什么是seo什么是sem
  • 安徽做公司网站哪家好聊城seo优化
  • wordpress 判断登录页面seo怎么收费的
  • 网站源代码怎么上传快手流量推广免费网站
  • 网站怎么做口碑提升神马seo关键词自然排名
  • 广州营销推广网站网站seo服务公司
  • vps除了做网站还能做什么找seo外包公司需要注意什么
  • 网站后台管理系统界面百度seo如何优化关键词
  • 塑料瓶手工制作大全搜索引擎优化案例分析
  • 建立网站图片seo职业技能培训班
  • 优创智汇高端网站建设电话怎么样电销系统
  • 网站备案主体授权书跨境电商seo什么意思
  • 线上推广有哪些方式绍兴seo排名
  • 专业网站定制平台建站软件可以不通过网络建设吗
  • 有没有手机做任务赚钱的网站公司网站建站要多少钱
  • 腾讯云wordpress升级慢长沙网址seo
  • 网站建设工作小组推进表如何查询网站收录情况
  • 工厂做网站优化大师怎么删除学生
  • 做网站 搜索引擎品牌网络推广怎么做
  • 中学生制作的网站外贸网站建设推广公司
  • 做网站公司上海万网域名官网
  • 网站密钥怎么做上海全国关键词排名优化
  • 企业管理咨询服务机构seo哪家强
  • 手机网站维护费合肥做网站公司哪家好
  • 新公司注册流程及材料及步骤东莞优化怎么做seo
  • asp加dw做网站如何建立自己的网站
  • 做画册的网站西安网络推广seo0515