用Java JMC控制台分析线程阻塞原因
问题
今天在玩dianping-CAT框架时,发现请求某个页面的时候,发生了阻塞。浏览器得不到响应。
环境
本地Tomcat 8 , Windows 系统。
解决
启动jmc 控制台,找到BLOCKED 线程:
然后定位到代码:
发现是我昨天加了一行代码:
System.out.println();
private TransactionReport getHourlyReport(Payload payload) {
String domain = payload.getDomain();
String ipAddress = payload.getIpAddress();
ModelRequest request = new ModelRequest(domain, payload.getDate()).setProperty("type", payload.getType())
.setProperty("ip", ipAddress);
if (m_service.isEligable(request)) {
ModelResponse<TransactionReport> response = m_service.invoke(request);
TransactionReport report = response.getModel();
if (report == null) {
System.out.println("m_service: " + m_service.getName() + " class: " + m_service.getClass().getCanonicalName());
throw new RuntimeException("Internal error: no response data for " + request + "!");
}
return report;
} else {
throw new RuntimeException("Internal error: no eligable transaction service registered for " + request + "!");
}
}
这个位置导致请求线程阻塞了。