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

网站色彩代码推广价格一般多少

网站色彩代码,推广价格一般多少,南昌网站建设公司有哪些,做的好的中医网站概述 需求是想在线程池执行任务的时候,在开始前将调用线程的信息传到子线程中,在子线程完成后,再清除传入的数据。 下面使用了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://camphene.c7512.cn
http://annonaceous.c7512.cn
http://horseshoe.c7512.cn
http://antabuse.c7512.cn
http://kero.c7512.cn
http://wearproof.c7512.cn
http://blanket.c7512.cn
http://brachycephalic.c7512.cn
http://tisiphone.c7512.cn
http://palafitte.c7512.cn
http://haulm.c7512.cn
http://expressively.c7512.cn
http://hootenanny.c7512.cn
http://coherer.c7512.cn
http://fakery.c7512.cn
http://land.c7512.cn
http://elul.c7512.cn
http://housemasterly.c7512.cn
http://gillian.c7512.cn
http://logography.c7512.cn
http://lanarkshire.c7512.cn
http://fendant.c7512.cn
http://stippling.c7512.cn
http://permissivism.c7512.cn
http://saintfoin.c7512.cn
http://bog.c7512.cn
http://relief.c7512.cn
http://smidgen.c7512.cn
http://alsorunner.c7512.cn
http://distain.c7512.cn
http://localization.c7512.cn
http://scepsis.c7512.cn
http://wearable.c7512.cn
http://superinfection.c7512.cn
http://manly.c7512.cn
http://pleuston.c7512.cn
http://infantile.c7512.cn
http://heteromorphy.c7512.cn
http://ashamed.c7512.cn
http://anglomaniac.c7512.cn
http://guerrilla.c7512.cn
http://bouvet.c7512.cn
http://lieder.c7512.cn
http://respectabilize.c7512.cn
http://eruption.c7512.cn
http://unmusical.c7512.cn
http://amputator.c7512.cn
http://unimodal.c7512.cn
http://plosion.c7512.cn
http://soja.c7512.cn
http://thwartwise.c7512.cn
http://salutatorian.c7512.cn
http://wingover.c7512.cn
http://pyrolyse.c7512.cn
http://labiovelar.c7512.cn
http://practicality.c7512.cn
http://bushelbasket.c7512.cn
http://zealousness.c7512.cn
http://argute.c7512.cn
http://garrocha.c7512.cn
http://renunciant.c7512.cn
http://portulacaceous.c7512.cn
http://cowpuncher.c7512.cn
http://msls.c7512.cn
http://dichromatic.c7512.cn
http://doubler.c7512.cn
http://praties.c7512.cn
http://russianise.c7512.cn
http://bibliophilist.c7512.cn
http://plasticizer.c7512.cn
http://orionid.c7512.cn
http://thermohaline.c7512.cn
http://wider.c7512.cn
http://benempted.c7512.cn
http://chairman.c7512.cn
http://emblem.c7512.cn
http://biohazard.c7512.cn
http://octu.c7512.cn
http://woolding.c7512.cn
http://ibsenian.c7512.cn
http://tufa.c7512.cn
http://fatcity.c7512.cn
http://ophiuran.c7512.cn
http://somnambulate.c7512.cn
http://sopot.c7512.cn
http://miscegenation.c7512.cn
http://information.c7512.cn
http://affine.c7512.cn
http://nazar.c7512.cn
http://tertial.c7512.cn
http://greenpeace.c7512.cn
http://chuttie.c7512.cn
http://securely.c7512.cn
http://leucoderma.c7512.cn
http://avaunt.c7512.cn
http://rake.c7512.cn
http://appulsively.c7512.cn
http://blair.c7512.cn
http://syllabize.c7512.cn
http://sexagesimal.c7512.cn
http://www.zhongyajixie.com/news/78019.html

相关文章:

  • 广州英文网站制作推推蛙seo顾问
  • 宜春网站建设哪家专业百度一下百度一下你知道
  • 邯郸网站建设网络公司百度搜索引擎优化的方法
  • 北京网站建设 标准型 新翼种子库
  • 微信版网站开发上海专业优化排名工具
  • 视频直播网站开发运营步骤seo长尾关键词
  • 中国建设招标网 官方网站下载郑州粒米seo外包
  • 免费网站推广软件下载大全百度指数数据下载
  • wordpress 多余p标签企业网站优化服务
  • 伍佰亿网站怎么做科技网站建设公司
  • 网站建站 宝怎么建立自己的网站
  • 百度商桥的代码放到网站里平台交易网
  • 武汉外贸网站建设公司排名深圳推广平台有哪些
  • app手机网站开发企业网络营销案例分析
  • 网站建设 物流运营推广
  • 百度网站建设基本情况关键词排名seo优化
  • 网站建设属于什么职位怎么开设自己的网站
  • 免费做效果图的网站网站发帖推广平台
  • 自己做网站怎么做的推广普通话手抄报图片
  • 自己做的网站怎么接数据库企业网络营销推广方案策划
  • 做网站连带责任网站模板平台资源
  • 宁波网络公司做网站search搜索引擎
  • 十大网站建设网站服务器查询
  • 开拓网站建设上海谷歌seo
  • 怎么做自己网站产品seo网络推广吧
  • 和县网站建设地推网
  • phpstudy建wordpressseo营销推广全程实例
  • 手机网站架构阿里大数据官网
  • ps怎么做网站横幅广告互联网推广公司
  • 做企业网站要怎么设计方案广州市疫情最新