你讲的很详细,谢谢了 :) 我现在的问题是,Tomcat是如何处理超时的线程的。想JDK的线程池,一旦submit之后就不管了,如果有future返回,也只是监听一下,即使超时了,也不会去管。 所以我就是想指导tomcat是如何处理线程超时的。否则线程池的资源只会越来越少!这你真就得自己进源码看看啦 作为程序员我感觉如果有这样的激情不去探究真的很难成为一名优秀的程序员吧 当然我这里以前也有用自己编译的tomcat7,帮你进去大概看了看 顺便说句你真的该自己去探索这样的问题 别人说再多也没用自己探索得来的那样充实 收获大。因为tomcat的源码是ant管理的 你只要用ant编译一下就ok啦。你可以通过调试的方式,然后查看其调用堆栈,很容易发现ThreadPoolExecuter这个类,因为工作忙的原因,我也没仔细看 你可以进去看看 我觉得这是任何人都不应该代替你的地方。我吧它的注释贴出来 看看你应该也大体明白了If the pool currently has more than corePoolSize threads, * excess threads will be terminated if they have been idle for more * than the keepAliveTime (see {@link * ThreadPoolExecutor#getKeepAliveTime}). This provides a means of * reducing resource consumption when the pool is not being actively * used. If the pool becomes more active later, new threads will be * constructed. This parameter can also be changed dynamically using * method {@link ThreadPoolExecutor#setKeepAliveTime}. Using a value * of <tt>Long.MAX_VALUE</tt> {@link TimeUnit#NANOSECONDS} effectively * disables idle threads from ever terminating prior to shut down. By * default, the keep-alive policy applies only when there are more * than corePoolSizeThreads. But method {@link * ThreadPoolExecutor#allowCoreThreadTimeOut(boolean)} can be used to apply * this time-out policy to core threads as well, so long as * the keepAliveTime value is non-zero.从这里也可以看出 超时的线程肯定会被回收掉呢 要不然你想想也清楚win32最大理论支持的4G内存寻址空间,即便一个线程开销2M,最多也就2000个线程。加上线程的上下文就切换,时间,空间的浪费是可想而知的。你再怎么开线程也不可能让你超过最大线程数呢
而且我先要的答案是,request超时,Tomcat在代码层面是怎么去处理的。
是怎么把这个线程资源给释放的
http超时挺长的啊,5分钟是有了。
如果你说的http 408超时(客户端没有在服务器预备等待的时间内完成一个请求的发送。)的话,那还没进入doPost/doGet
所以我才想到看看Tomcat中多线程处理request,超时会怎么样。
这一块得深入到源码层级才能知道他的处理方式,所以我走走捷径,问问大神们
我现在的问题是,Tomcat是如何处理超时的线程的。想JDK的线程池,一旦submit之后就不管了,如果有future返回,也只是监听一下,即使超时了,也不会去管。
所以我就是想指导tomcat是如何处理线程超时的。否则线程池的资源只会越来越少!
我现在的问题是,Tomcat是如何处理超时的线程的。想JDK的线程池,一旦submit之后就不管了,如果有future返回,也只是监听一下,即使超时了,也不会去管。
所以我就是想指导tomcat是如何处理线程超时的。否则线程池的资源只会越来越少!这你真就得自己进源码看看啦 作为程序员我感觉如果有这样的激情不去探究真的很难成为一名优秀的程序员吧 当然我这里以前也有用自己编译的tomcat7,帮你进去大概看了看 顺便说句你真的该自己去探索这样的问题 别人说再多也没用自己探索得来的那样充实 收获大。因为tomcat的源码是ant管理的 你只要用ant编译一下就ok啦。你可以通过调试的方式,然后查看其调用堆栈,很容易发现ThreadPoolExecuter这个类,因为工作忙的原因,我也没仔细看 你可以进去看看 我觉得这是任何人都不应该代替你的地方。我吧它的注释贴出来 看看你应该也大体明白了If the pool currently has more than corePoolSize threads,
* excess threads will be terminated if they have been idle for more
* than the keepAliveTime (see {@link
* ThreadPoolExecutor#getKeepAliveTime}). This provides a means of
* reducing resource consumption when the pool is not being actively
* used. If the pool becomes more active later, new threads will be
* constructed. This parameter can also be changed dynamically using
* method {@link ThreadPoolExecutor#setKeepAliveTime}. Using a value
* of <tt>Long.MAX_VALUE</tt> {@link TimeUnit#NANOSECONDS} effectively
* disables idle threads from ever terminating prior to shut down. By
* default, the keep-alive policy applies only when there are more
* than corePoolSizeThreads. But method {@link
* ThreadPoolExecutor#allowCoreThreadTimeOut(boolean)} can be used to apply
* this time-out policy to core threads as well, so long as
* the keepAliveTime value is non-zero.从这里也可以看出 超时的线程肯定会被回收掉呢 要不然你想想也清楚win32最大理论支持的4G内存寻址空间,即便一个线程开销2M,最多也就2000个线程。加上线程的上下文就切换,时间,空间的浪费是可想而知的。你再怎么开线程也不可能让你超过最大线程数呢