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

北京做网站需要多少钱重庆建设工业集团

北京做网站需要多少钱,重庆建设工业集团,西安网评,东莞企业公司网站建设线程池的几个重要的参数: 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.yayakq.cn/news/613001/

相关文章:

  • 网站设计制作 联系做网站上哪买空间
  • 微网站技术亚洲风影视传媒有限公司辽宁
  • 黄页网站营销网站导航怎么用ulli做
  • 怎么在微信公众号上做网站潍坊人才招聘网
  • 备案时网站名称可以重复吗目前徐州有多少网架公司
  • 徐州专业建站公司小程序备用金
  • 免费ppt模板的网站中华网军事网
  • 全国做网站公司前十名建设工程公司logo设计
  • 网站开发需求模板安卓系统开发培训
  • 广西网站建设软件推广网页设计是做什么
  • 国内炫酷网站设计广告网站模板下载不了
  • 中信建设有限责任公司华美分公司兰州网络seo
  • 中企动力网站建设 长春网上做网站怎么做下拉菜单
  • 开网上授课的网站应该怎么做邯郸oa办公系统
  • 外贸国际网站推广施工企业工作分解结构
  • 网站建设市场调研框架公司网站维护分工
  • 做食品网站wordpress 301
  • 微网站制作多少钱做网站外包最牛的公司
  • 二级网站都在一台服务器怎么做域名dw做的网站怎么放到服务器上
  • 个人做电影网站服务器放国外安全吗高端网站建设 深圳
  • 登录自己网站的后台 wordpress厦门网站建设ui
  • 模拟炒股网站开发alexa排名分析
  • html做校园网站网站右下角弹窗代码
  • 网站制作哪里好薇廊坊安次区网站建设公司
  • 菏泽网站建设费用房地产网站开发商
  • 做返利网站能赚钱么平台搭建需要什么技术
  • 网站备案网站前置审批网站建设公司 2018
  • 天津网站建设培训课件网站源码本地演示
  • 网站被挂黑链制作网站书签怎么做
  • 个人网站建设基本教程flash个人网站