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

深圳网站设计公司专业吗网站查询系统

深圳网站设计公司专业吗,网站查询系统,移动互联网的概念,wordpress主题 使用教程文章目录 线程池的拒绝策略AbortPolicy拒绝策略:CallerRunsPolicy拒绝策略:DiscardOldestPolicy拒绝策略:DiscardPolicy拒绝策略: 线程池的拒绝策略 若在线程池当中的核心线程数已被用完且阻塞队列已排满,则此时线程池…

文章目录

    • 线程池的拒绝策略
      • AbortPolicy拒绝策略:
      • CallerRunsPolicy拒绝策略:
      • DiscardOldestPolicy拒绝策略:
      • DiscardPolicy拒绝策略:

线程池的拒绝策略

若在线程池当中的核心线程数已被用完且阻塞队列已排满,则此时线程池的线程资源已耗尽,线程池没有足够的线程资源执行新的任务。

所以为了保证操作系统的安全性,线程池将通过拒绝策略来处理新添加的线程任务。

JDK 中内置的拒绝策略有 AbortPolicy,CallerRunsPolicy、DiscardOldestPolicy、DiscardPolicy 这4种,默认的拒绝策略在 ThreadPoolExecutor 中作为内部类来进行提供的,在默认的拒绝策略都不能满足应用的需求时,也可以自定义拒绝策略。

AbortPolicy拒绝策略:

该策略会直接抛出异常,阻止系统正常工作。

jdk源码:

    /*** A handler for rejected tasks that throws a* {@code RejectedExecutionException}.*/public static class AbortPolicy implements RejectedExecutionHandler {/*** Creates an {@code AbortPolicy}.*/public AbortPolicy() { }/*** Always throws RejectedExecutionException.** @param r the runnable task requested to be executed* @param e the executor attempting to execute this task* @throws RejectedExecutionException always*/public void rejectedExecution(Runnable r, ThreadPoolExecutor e) {throw new RejectedExecutionException("Task " + r.toString() +" rejected from " +e.toString());}}

CallerRunsPolicy拒绝策略:

如果线程池的线程数量达到上限,该策略会把任务队列中的任务放在调用者线程(如main函数)当中运行。

jdk源码:

    /*** A handler for rejected tasks that runs the rejected task* directly in the calling thread of the {@code execute} method,* unless the executor has been shut down, in which case the task* is discarded.*/public static class CallerRunsPolicy implements RejectedExecutionHandler {/*** Creates a {@code CallerRunsPolicy}.*/public CallerRunsPolicy() { }/*** Executes task r in the caller's thread, unless the executor* has been shut down, in which case the task is discarded.** @param r the runnable task requested to be executed* @param e the executor attempting to execute this task*/public void rejectedExecution(Runnable r, ThreadPoolExecutor e) {if (!e.isShutdown()) {r.run();}}}

DiscardOldestPolicy拒绝策略:

该策略将移除最早的一个请求,也就是即将被执 行的任务,然后并尝试再次提交当前的任务。

jdk源码:

    /*** A handler for rejected tasks that discards the oldest unhandled* request and then retries {@code execute}, unless the executor* is shut down, in which case the task is discarded.*/public static class DiscardOldestPolicy implements RejectedExecutionHandler {/*** Creates a {@code DiscardOldestPolicy} for the given executor.*/public DiscardOldestPolicy() { }/*** Obtains and ignores the next task that the executor* would otherwise execute, if one is immediately available,* and then retries execution of task r, unless the executor* is shut down, in which case task r is instead discarded.** @param r the runnable task requested to be executed* @param e the executor attempting to execute this task*/public void rejectedExecution(Runnable r, ThreadPoolExecutor e) {if (!e.isShutdown()) {e.getQueue().poll();e.execute(r);}}}

DiscardPolicy拒绝策略:

丢弃当前线程任务而不做任何处理。如果系统允许在资源不足的情况下丢弃部分任务,则这将是保障系统安全,稳定的一种很好的方案。

jdk源码:

    /*** A handler for rejected tasks that silently discards the* rejected task.*/public static class DiscardPolicy implements RejectedExecutionHandler {/*** Creates a {@code DiscardPolicy}.*/public DiscardPolicy() { }/*** Does nothing, which has the effect of discarding task r.** @param r the runnable task requested to be executed* @param e the executor attempting to execute this task*/public void rejectedExecution(Runnable r, ThreadPoolExecutor e) {}}

以上4种拒绝策略均是实现的 RejectedExecutionHandler 接口,来实现拒绝策略,若无法满足实际需要,则用户就可以自己自定义来实现拒绝策略。

http://www.yidumall.com/news/92354.html

相关文章:

  • 外贸做网站建设哪家好百度sem推广
  • 什么网站广告做多网络营销推广方案步骤
  • 直销系统建设成都百度推广优化创意
  • wbs分析网站建设网站优化推广
  • 济南汇网站群软件外包网站
  • 上海做淘宝网站建设手机百度高级搜索
  • aspcms中引文 网站修改配置黄金网站app大全
  • wordpress 获取链接北京seo优化公司
  • 高端企业网站建设流程泰安seo排名
  • 做微信公众号页面的网站视频号链接怎么获取
  • 无休网站建设河北网站优化公司
  • 常熟做网站多少钱按短视频营销推广方案
  • 武汉做机床的公司网站江西优化中心
  • 互联网 现代农业网站建设常德论坛网站
  • 怎么用burp suite做网站扫描友情链接英文翻译
  • 官网招聘和招聘网站做网站seo推广公司
  • 定制网站报价淘宝怎么优化关键词排名
  • 唐山哪个公司可以制作网站淘宝指数转换
  • 网站别人备案怎么办理网络推广的优势有哪些
  • 做网站应该学什么专业网站推广优化公司
  • 大型网站建设平台推广宣传文案
  • 网站做的好不好数据百度热搜排名
  • wordpress传不上站点千峰培训出来好就业吗
  • 襄阳做网站 优帮云百度推广费用多少
  • 免费推广引流平台下载seo的方式包括
  • 行业门户网站建设方案电商网站前端页面内容编写
  • 建设b2b网站需要多少钱推销产品怎么推广
  • 泰安集团网站建设谷歌商店下载官方
  • 微信做单页的网站百度关键词价格查询软件
  • 怎么做网站变更防晒霜营销软文