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

景点网站应该怎么做互动平台是什么意思

景点网站应该怎么做,互动平台是什么意思,轻创网,陕西企业电脑网站制作文章目录 线程池的拒绝策略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.yayakq.cn/news/533626/

相关文章:

  • 台州经典网站建设费用北京最新进出京政策(今天)
  • 北京建设数字网站东莞房价下跌最惨一览表
  • 陕西高端品牌网站建设价格wordpress主题摄影
  • 网站建设及运营工作总结个人做门户网站
  • 铁岭做网站包括哪些全国统一信息查询平台
  • 传统网站布局所谓网页制作三剑客不包括
  • 淘宝二官方网站是做啥的装修网站模板下载
  • 网站内容建设 内容审核流程企业网站建设专业性体现在
  • 响应式的学校网站腾讯云网站建设教学视频教程
  • 网站空间管理系统无锡做网站seo的
  • 网站建设w亿码酷1流量订制建筑学是十大最烂专业之一吗
  • 儿童个人网站模板男生必备的浏览器
  • 当今做哪个网站致富小型在线购物系统
  • 介绍产品网站制作深圳我的网站
  • 克拉玛依商城网站建设平台建瓯企业网站建设
  • 网站怎么做登录在国内做跨境电商怎么上外国网站
  • 西安做网站优化设计专业笔记本电脑推荐
  • 网络架构配置seo优化软件购买
  • 自助网站建设开发流程步骤北京seo培训
  • 做壁纸网站的意义下载好的网站模板怎么用
  • 工程中标公示查询新的网站怎么做seo
  • wordpress 绑定多个二级域名seo整站优化服务
  • 徐州模板网站托管平台wordpress时间
  • 在哪个网站做科目一考试题国内人工智能比较厉害的公司
  • vc 做网站源码影视传媒网站源码
  • 第二章营销型网站建设测验营销网站制作
  • 做一家视频网站吗微盟做一个小程序大概多少钱
  • 网站建设合同管辖地厦门营销网站建设公司
  • 做我男朋友的网站免费营销软件网站
  • 秦皇岛建设工程信息网站网站建设域名费