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

成都网站建设 冠辰百度在西安的公司叫什么

成都网站建设 冠辰,百度在西安的公司叫什么,wordpress重装教程,郴州网站制作公司有哪些线程池的几个重要的参数: 1、corePoolSize:线程池的核心线程数(也是默认线程数) 2、maximumPoolSize:最大线程数 3、keepAliveTime:允许的线程最大空闲时间(单位/秒) 线程池内部是…

线程池的几个重要的参数:

1、corePoolSize:线程池的核心线程数(也是默认线程数)

2、maximumPoolSize:最大线程数

3、keepAliveTime:允许的线程最大空闲时间(单位/秒)

线程池内部是通过队列+线程实现的,当我们利用线程池执行任务时:

  • 如果此时线程池中的线程数量小于corePoolSize,即使线程池中的线程都处于空闲状态,也要创建新的线程来处理被添加的任务,

  • 如里此时线程池中的线程数量等于corePoolSize,但是缓冲队列workQueue未满,那么任务被放入缓冲队列。

  • 如果此时线程池中的线程数量大于等于corePoolSize,缓中队列workQueue满,并且线程池中的数量小于maximumPooISize,建新的线程来外理被添加的任务。

  • 如果此时线程池中的线程数量大于corePoosize,缓冲队列workQueue满,并目线程池中的数量等于maximumPoosize,那么通过 handler所指定的策略来处理此任务。

  • 当线程池中的线程数量大于 corePoolsize时,如果某线程空闲时间超过keepAliveTime,线程将被终止。这样,线程可以动态的调整池中的线程数。

线程池的拒绝策略:指的是RejectedExecutionHandler接口的实现类。

在线程池接口的源代码中,可以发现ThreadPoolExecutor接口内置了4种拒绝策略。

package java.util.concurrent;public class ThreadPoolExecutor extends AbstractExecutorService {/*** 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();}}}/*** 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());}}/*** 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) {}}/*** 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);}}}}

四种拒绝策略的相关说明:

1、AbortPolicy:

默认。拒绝这个任务,并且抛出RejectedExecutionException异常。

2、DiscardPolicy:

队列满了,丢掉任务,不会抛出异常!

3、DiscardOldestPolicy
队列满了,尝试去和最早的竞争,也不会抛出异常!
抛弃最老任务策略,也就是说如果队列满了,就会将最早进入队列的任务抛弃,从队列中腾出空间,再尝试加入队列。因为队列是队尾进、队头出,队头元素是最老的,所以每次都是移除队头元素后再尝试入队。

4、CallerRunsPolicy
调用者执行策略。在新任务被添加到线程池时,如果添加失败,那么提交任务的线程会自己去执行该任务,不会使用线程池中的线程去执行新任务。

http://www.dinnco.com/news/8054.html

相关文章:

  • markdowm wordpress关键词seo优化软件
  • 开发一个app有多难seopeixun
  • 包头网站设计公司深圳市网络品牌推广
  • 青岛seo做的好的网站关键词排名优化公司推荐
  • 购买网站空间关键词排名优化技巧
  • 网站关键词如何优化上首页游戏推广一个月能拿多少钱
  • wordpress调取某页面什么是seo站内优化
  • 做网站平台成本搜索优化
  • 如何用域名做网站访问国内外搜索引擎大全
  • 做网站怎么每天更新内容怎么创建自己的游戏网站
  • 延吉网站建设depawo营销网站建设选择原则
  • 阿里云做网站个人网络销售平台
  • 医疗美容网站建设方案关键词排名怎么上首页
  • 手机网站的建设软文营销推广
  • 寮步网站建设公司百度seo优化是什么
  • 盐田网站建设seo课程简介
  • 登陆不了建设银行网站如何做好网站推广优化
  • 公司在网站做广告怎么做分录长沙seo咨询
  • 信阳网站建设找汉狮上海谷歌seo推广公司
  • 网站开发 chtml静态网页制作
  • 网页设计类网站淘宝关键词排名优化技巧
  • 国外有做塑料粒子的网站吗seo查询网站是什么
  • 广西网站推广青岛网站建设
  • 门户网站建设成本免费顶级域名注册
  • 企业网站seo诊断seo关键词排名优化品牌
  • 定做网站多少钱seo关键词查询工具
  • wordpress英文自动采集遵义网站seo
  • 无锡网页建站公司排名第一的助勃药
  • 国内做的好看的网站设计seo知识是什么意思
  • 鸡西市法院的网站建设公司网络营销试卷