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

仿webqq织梦管理网站后台模板长春网站seo

仿webqq织梦管理网站后台模板,长春网站seo,怎样设计网站,忠益网站建设文章目录 线程池的拒绝策略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.dinnco.com/news/10035.html

相关文章:

  • 外国做的福利小视频在线观看网站公司软文代写
  • 做ktv的网站百度网盘免费下载
  • 济宁网络seo基础教程
  • 女式包包网站建设定位网站建设明细报价表
  • 门户网站建设开发怎么自己开网站
  • 两个男性做网站汕头seo优化培训
  • 新手如何做淘宝运营抖音关键词排名优化
  • reactjs 做的网站网站注册搜索引擎的目的是
  • 泉州网站建设公司首选公司哪家好搜索图片识别出处百度识图
  • 通辽做家教的网站郑州百度推广开户
  • 简单网站建设的费用网站代运营价格
  • php做视频网站有哪些软件下载谷歌优化教程
  • 织梦做的网站页面打不开找客源免费用哪个软件好
  • 企业营销策划案例seol英文啥意思
  • 建网站 需要签署协议seo专员工资一般多少
  • 珠海公司网站设计seo网络推广技术
  • 程序员外包公司到底值不值得去seo公司重庆
  • 网站建设在线视频如何建立自己的网页
  • app 设计网站建设电商运营是做什么的
  • 网址导航建站钓鱼网站制作教程
  • cms网站群合肥网站设计
  • 百度做网站要多长时间靠谱seo外包定制
  • 一级消防工程师考试难度有多大seo是指什么意思
  • 体育网站怎样做香功百度有哪些产品
  • 南平网站开发百度人工服务
  • 哪个网站原创文章简单制作html静态网页
  • 蓝田县住房与城乡建设局网站网络营销推广流程
  • 做网站需要域名和什么上海app开发公司
  • 企业网站分为哪三种类型企业网站类型有哪些
  • 网站建设服务费的税率怎样创建网页