Tomcat7 StuckThreadDetectionValve Function Analysis

Source: Internet
Author: User

Tomcat 7.0.14 was officially released this month. One of its most significant new features is the introduction of the StuckThreadDetectionValve feature, which helps analyze and check time-consuming requests or potentially request thread blocking.

StuckThreadDetectionValve is implemented by extending the Valve mechanism of Tomcat. The following is an analysis of the main source code for the implementation of this block code, to explore the implementation principles of this function.

The following is the core code snippet, but it is better understood in terms of implementation ideas. The valve intercepts all tomcat requests, and the execution thread is saved through an introduction to record the start time. At the same time, start the MonitoredThread thread to check the running time of the current request thread. Once the value exceeds the set value, it will be saved, in this way, we can easily obtain the inefficient request threads.

The overall class diagram is as follows:

The following are several important global attributes:

StuckCount Number of threads that may be blocked

Threshold Indicates the basis for judging the running time of the blocked thread. If the running time exceeds the upper limit, the thread in the environment is regarded as a blocked thread.

ActiveThreads Currently running thread

CompletedStuckThreadsQueue Blocked threads already executed

InvokeThe method code is as follows:

StuckCount Number of threads that may be blocked

Threshold Indicates the basis for judging the running time of the blocked thread. If the running time exceeds the upper limit, the thread in the environment is regarded as a blocked thread.

ActiveThreads Currently running thread

CompletedStuckThreadsQueue Blocked threads already executed

InvokeThe method code is as follows:

StuckCount Number of threads that may be blocked

Threshold Indicates the basis for judging the running time of the blocked thread. If the running time exceeds the upper limit, the thread in the environment is regarded as a blocked thread.

ActiveThreads Currently running thread

CompletedStuckThreadsQueue Blocked threads already executed

InvokeThe method code is as follows:

StuckCount Number of threads that may be blocked

Threshold Indicates the basis for judging the running time of the blocked thread. If the running time exceeds the upper limit, the thread in the environment is regarded as a blocked thread.

ActiveThreads Currently running thread

CompletedStuckThreadsQueue Blocked threads already executed

InvokeThe method code is as follows:

StuckCount may be the number of blocked threads

The basis for judging the running time of the threshold blocking thread. If the time limit is exceeded, the thread in the environment will be a blocking thread.

ActiveThreads is currently running.

CompletedStuckThreadsQueue blocking threads that have been executed

The invoke method code is as follows:

StuckCount may be the number of blocked threads

The basis for judging the running time of the threshold blocking thread. If the time limit is exceeded, the thread in the environment will be a blocking thread.

ActiveThreads is currently running.

CompletedStuckThreadsQueue blocking threads that have been executed

The invoke method code is as follows:

StuckCount may be the number of blocked threads

The basis for judging the running time of the threshold blocking thread. If the time limit is exceeded, the thread in the environment will be a blocking thread.

ActiveThreads is currently running.

CompletedStuckThreadsQueue blocking threads that have been executed

The invoke method code is as follows:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.