免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1441 | 回复: 1
打印 上一主题 下一主题

[Web] 求解tomcat线程池源码 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-07-22 21:05 |只看该作者 |倒序浏览
最近读tomcat源代码,其中线程池部分有一段完全看不懂,ThreadPoolExecutor.java源文件中的一个方法,不知道这个这个方法起什么作用,以及Context reload是什么意思,在什么情况下需要进行Context reload
  1. public void contextStopping() {
  2.         this.lastContextStoppedTime.set(System.currentTimeMillis());

  3.         // save the current pool parameters to restore them later
  4.         int savedCorePoolSize = this.getCorePoolSize();
  5.         TaskQueue taskQueue =
  6.                 getQueue() instanceof TaskQueue ? (TaskQueue) getQueue() : null;
  7.         if (taskQueue != null) {
  8.             // note by slaurent : quite oddly threadPoolExecutor.setCorePoolSize
  9.             // checks that queue.remainingCapacity()==0. I did not understand
  10.             // why, but to get the intended effect of waking up idle threads, I
  11.             // temporarily fake this condition.
  12.             taskQueue.setForcedRemainingCapacity(Integer.valueOf(0));
  13.         }

  14.         // setCorePoolSize(0) wakes idle threads
  15.         this.setCorePoolSize(0);

  16.         // wait a little so that idle threads wake and poll the queue again,
  17.         // this time always with a timeout (queue.poll() instead of
  18.         // queue.take())
  19.         // even if we did not wait enough, TaskQueue.take() takes care of timing
  20.         // out, so that we are sure that all threads of the pool are renewed in
  21.         // a limited time, something like
  22.         // (threadKeepAlive + longest request time)
  23.         try {
  24.             Thread.sleep(200L);
  25.         } catch (InterruptedException e) {
  26.             // yes, ignore
  27.         }

  28.         if (taskQueue != null) {
  29.             // ok, restore the state of the queue and pool
  30.             taskQueue.setForcedRemainingCapacity(null);
  31.         }
  32.         this.setCorePoolSize(savedCorePoolSize);
  33.     }
复制代码

论坛徽章:
0
2 [报告]
发表于 2013-07-22 23:31 |只看该作者
我自己顶一下
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP