在Tomcat中识别并杀死卡住的线程

时间:2015-10-05 07:09:03

标签: tomcat

我们正面临着tomcat中长时间运行的线程的问题。我们正在使用Tomcat - 7.0.47.Tomcat管理器显示当前忙线程:200,应用程序由于这些长时间运行的线程而卡住。我们在server.xml()中实现了StuckThreadDetectionValve,但它没有帮助。所以我们通过从catalina扩展StuckThreadDetectionValve来实现自定义StuckThreadDetectionValve,它只进入“constructor”,“initInternal”,并且在“invoke”中(当动作触发时),即使在阈值时间之后它也不会运行“getStuckThreadNames()”。如何实现相同。有没有办法检测卡住线程并杀死它们?

我的自定义Valve如下:

public class StuckThreadDetection extends StuckThreadDetectionValve { StuckThreadDetection stuckThreadDetection;

public StuckThreadDetection()
{
    System.out.println("in StuckThreadDetection constructor");

}

public void invoke(Request request, Response response) throws IOException,
        ServletException
{
    System.out.println("in invoke...");

    getNext().invoke(request, response);
}

@Override
protected void initInternal() throws LifecycleException
{
    System.out.println("In initInternal");
    super.initInternal();
}

@Override
public String[] getStuckThreadNames()
{
    System.out.println("in getStuckThreadNames...");
    String[] listStuckedThread = this.getStuckThreadNames();

    for (String threadName : listStuckedThread)
    {
        System.out.println(threadName);
    }

    return listStuckedThread;

}

@Override
public String getInfo()
{
    System.out.println("In getInfo");
    return super.getInfo();
}
}

0 个答案:

没有答案