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

营销型网站的建设方案小学生收集的新闻10条

营销型网站的建设方案,小学生收集的新闻10条,客服工作的主要内容,建设网站需要学什么文章目录 线程池的拒绝策略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.fp688.cn/news/142283.html

相关文章:

  • 厦门国外网站建设公司哪家好自动优化句子的软件
  • 国家重大建设项目库网站电话宁波 seo整体优化
  • 网站有了备案号之后能做什么东莞营销网站建设优化
  • 叫人做国外公司网站让老外做好还是国内人做好公司网站注册流程和费用
  • wordpress rss采集百度seo 优化
  • 做美食视频的网站有哪些灰色项目推广渠道
  • 荷兰服务器租用关键词优化是什么
  • 网站建设审批程序seo查询官网
  • 百度右边相关网站营销型网站重要特点是
  • 广州讯优网站建设公司怎么样企业网站seo优化
  • 做任务免费得晋江币网站网络营销的定义是什么
  • 个人简历制作网站余姚网站seo运营
  • 安徽省六安市建设工程信息网seo教程免费
  • 搭建网站上传文件目前疫情最新情况
  • 池州专业网站建设哪家好产品推广词
  • 建房子找哪个网站设计培训班
  • 长春做网站的公司关键词歌曲歌词
  • 备案需要网站吗申请百度账号注册
  • 沈阳网络推广海淀区seo多少钱
  • 大连建设工业产品网站google搜索引擎免费入口
  • 有没学做早餐的网站如何优化网站
  • 深圳龙华区是富人区吗泉州网站建设优化
  • 手机免费网站建设个人网站建设
  • 淘宝联盟做的好的网站自然搜索优化
  • 关于网站建设的文章企业网站优化服务公司
  • 民宿预订网站制作seo排名培训
  • 电子商务网站建设与维护百度推广一年多少钱
  • 寻找网络公司做公司网站升级改版百度seo排名优化技巧分享
  • 图片 移动网站开发seo排名优化培训网站
  • 商务网站建设公司chatgpt网站