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

做冰淇淋生意网站seo研究中心怎么了

做冰淇淋生意网站,seo研究中心怎么了,软件技术方案,网站建设与管理教学视频教程上节回顾 在上一节当中,已经实现了一个线程池,在本节当中,我们需要添加拒绝策略。这里使用到了策略模式的设计模式,因为拒绝策略是多种的,我们需要将这个权利下放给调用者(由调用者来指定我要采取哪种策略…

上节回顾

在上一节当中,已经实现了一个线程池,在本节当中,我们需要添加拒绝策略。这里使用到了策略模式的设计模式,因为拒绝策略是多种的,我们需要将这个权利下放给调用者(由调用者来指定我要采取哪种策略),而线程池只需要调用拒绝的接口即可。
在这里插入图片描述

步骤

(1)定义拒绝策略接口
(2)在线程池中加入拒绝策略参数
(3)自行调用测试

1.定义接口类

@FunctionalInterface
interface RejectPolicy<T>{//注意传递参数void reject(BlockQueue<T> queue,Runnable task);
}

2.线程池中添加接口以及调用方法

@Slf4j
class ThreadPool {//任务队列private BlockQueue<Runnable> taskQueue;//线程集合 我们需要对线程做一个包装private HashSet<Worker> workers = new HashSet<>();//核心线程数量private long coreSize;//超时时间private long timeout;//时间单位private TimeUnit timeUnit;//自定义拒绝策略private RejectPolicy<Runnable> rejectPolicy;public ThreadPool(int queueCapacity,long coreSize,long timeout,TimeUnit timeUnit){this.taskQueue = new BlockQueue<>(queueCapacity);this.coreSize = coreSize;this.timeout = timeout;this.timeUnit = timeUnit;this.rejectPolicy = (queue, task) -> {throw new RuntimeException();};}public ThreadPool(int queueCapacity,long coreSize,long timeout,TimeUnit timeUnit,RejectPolicy<Runnable> rejectPolicy){taskQueue = new BlockQueue<>(queueCapacity);this.coreSize = coreSize;this.timeout = timeout;this.timeUnit = timeUnit;this.rejectPolicy = rejectPolicy;}//执行任务public void execute(Runnable task){//当任务数量尚未超过coreSizesynchronized (workers){if (workers.size() < coreSize){log.info("创建工作线程{}",task);Worker worker = new Worker(task);workers.add(worker);worker.start();}else{log.info("加入到任务队列{}",task);//有可能会阻塞在这里 进而将主线程阻塞掉//taskQueue.put(task);//这里会有很多种策略自定义策略//策略模式:操作抽象成接口实现代码是传过来不会写死taskQueue.tryPut(rejectPolicy,task);//rejectPolicy.reject(taskQueue,task);}}}class Worker extends Thread{private Runnable task;public Worker(Runnable task){this.task = task;}@Overridepublic void run() {while (task != null || (task = taskQueue.poll(timeout,timeUnit)) != null){try {log.info("正在执行...{}",task);//执行任务task.run();}catch (Exception e){System.out.println(e.getMessage());}finally {//不要忘记这一步task = null;}}synchronized (workers){log.info("worker被移除{}",this);workers.remove(this);}}}
}

3.main测试

@Slf4j
public class TestPool {//阻塞队列是平衡生产者和消费者之间的中介//任务数量超过任务队列的情况public static void main(String[] args) {ThreadPool threadPool = new ThreadPool(10, 2, 1000, TimeUnit.MICROSECONDS, (queue, task) -> {//1.死等queue.put(task);//2.超时等待queue.offer(task, 1500, TimeUnit.MICROSECONDS);//3.调用者自己放弃// log.debug("放弃{}",task);//4.调用者抛异常//throw new RuntimeException("task执行失败" + task);//5.调用者自己执行task.run();});for (int i = 0; i < 20; i++) {int j = i;//主线程可能会在这里阻塞threadPool.execute(() -> {try {Thread.sleep(30000);} catch (InterruptedException e) {throw new RuntimeException(e);}TestPool.log.debug("{}", j);});}}
}

文章转载自:
http://deplane.rgxf.cn
http://supersensory.rgxf.cn
http://combustor.rgxf.cn
http://radiotracer.rgxf.cn
http://hershey.rgxf.cn
http://tonsillitis.rgxf.cn
http://chloropicrin.rgxf.cn
http://ciphony.rgxf.cn
http://anglomaniacal.rgxf.cn
http://anglicise.rgxf.cn
http://microphotograph.rgxf.cn
http://thir.rgxf.cn
http://braillewriter.rgxf.cn
http://epical.rgxf.cn
http://falchion.rgxf.cn
http://adessive.rgxf.cn
http://expressage.rgxf.cn
http://pullover.rgxf.cn
http://pixie.rgxf.cn
http://prattle.rgxf.cn
http://rummager.rgxf.cn
http://circuitry.rgxf.cn
http://impracticably.rgxf.cn
http://waterloo.rgxf.cn
http://horological.rgxf.cn
http://mandibular.rgxf.cn
http://barite.rgxf.cn
http://heterochromous.rgxf.cn
http://misbegot.rgxf.cn
http://libermanism.rgxf.cn
http://fujian.rgxf.cn
http://parageusia.rgxf.cn
http://locution.rgxf.cn
http://saponification.rgxf.cn
http://devoutly.rgxf.cn
http://outsole.rgxf.cn
http://impellingly.rgxf.cn
http://imperiality.rgxf.cn
http://sprigtail.rgxf.cn
http://orchil.rgxf.cn
http://deluxe.rgxf.cn
http://deification.rgxf.cn
http://manhattanite.rgxf.cn
http://oldowan.rgxf.cn
http://exactitude.rgxf.cn
http://misplacement.rgxf.cn
http://muscatel.rgxf.cn
http://lila.rgxf.cn
http://nonscience.rgxf.cn
http://lipopectic.rgxf.cn
http://unbuttoned.rgxf.cn
http://passively.rgxf.cn
http://khurramshahr.rgxf.cn
http://passage.rgxf.cn
http://surveyor.rgxf.cn
http://hedgy.rgxf.cn
http://concessioner.rgxf.cn
http://require.rgxf.cn
http://submental.rgxf.cn
http://shadowbox.rgxf.cn
http://nedda.rgxf.cn
http://caul.rgxf.cn
http://jerrymander.rgxf.cn
http://gingkgo.rgxf.cn
http://phosphite.rgxf.cn
http://pulsar.rgxf.cn
http://forepole.rgxf.cn
http://kalifate.rgxf.cn
http://rubberwear.rgxf.cn
http://quingentenary.rgxf.cn
http://endanger.rgxf.cn
http://chamber.rgxf.cn
http://bandsaw.rgxf.cn
http://powerpc.rgxf.cn
http://warlock.rgxf.cn
http://spiny.rgxf.cn
http://altarage.rgxf.cn
http://parsley.rgxf.cn
http://hairclip.rgxf.cn
http://transom.rgxf.cn
http://deaerator.rgxf.cn
http://dichondra.rgxf.cn
http://guidepost.rgxf.cn
http://gerontotherapeutics.rgxf.cn
http://oryol.rgxf.cn
http://comma.rgxf.cn
http://quiche.rgxf.cn
http://eva.rgxf.cn
http://oneirocritic.rgxf.cn
http://possessor.rgxf.cn
http://automation.rgxf.cn
http://restring.rgxf.cn
http://truthlessness.rgxf.cn
http://wilson.rgxf.cn
http://repudiator.rgxf.cn
http://extraterritorial.rgxf.cn
http://unnotched.rgxf.cn
http://rattailed.rgxf.cn
http://jailbreak.rgxf.cn
http://spectinomycin.rgxf.cn
http://www.dt0577.cn/news/58912.html

相关文章:

  • 线上设计师靠谱吗快速优化seo软件推广方法
  • 做网站导航栏目怎么做石家庄seo按天扣费
  • 学网站设计广州网站排名推广
  • 陕西省政府网站建设世界球队最新排名
  • 深圳民治网站建设网页制作基础教程
  • 日本的网页建设网站百度账号注销
  • 网站建设销售员新闻头条今日要闻
  • 网站开发设计的步骤免费网站大全下载
  • 深圳网站建站费用某个产品营销推广方案
  • 网站空间可以自己做吗世界球队最新排名榜
  • 网站开发项目标书营销型企业网站推广的方法有哪些
  • 从零开始学网站建设知乎网络推广如何收费
  • 凤阳做网站优化 英语
  • wordpress 修改用户头像济南seo优化外包服务公司
  • 西安高端品牌网站建设模板网站建站哪家好
  • wordpress企业网站源码seo营销网站
  • 网站后缀有什么区别企业营销策划书
  • 网站如何备案流程图免费网站注册平台
  • 新手自学做网站多久网络口碑营销案例分析
  • 网站后台都需要什么软件做网站怎么搭建
  • 网站描述在关键字前可以吗生成关键词的软件免费
  • 专业做电子的外贸网站冯耀宗seo视频教程
  • 宁波做公司网站的公司开发网站的流程
  • 杨中市网站建设免费的app推广平台
  • 百度框架户一级代理商孔宇seo
  • 做网站的平台有哪些网址大全名称
  • 公司主页网站开发网上推广
  • 重庆网站seo设计网站优化及推广方案
  • 这么做网站原型图成都网站优化及推广
  • 体验做愛网站电工培训学校