我们的猫没有回复任何请求。当我使用"jstack“打印堆栈信息时,我得到了以下信息。我发现它在"Thread.sleep(long)“上被屏蔽了。我认为应该是"TIMED_WAITING“。为什么?
Thread 24836: (state = BLOCKED)
- java.lang.Thread.sleep(long) @bci=0 (Compiled frame; information may be imprecise)
- com.lagou.base.proxy.MasterTemplateContainer.checkMaster(org.springframework.orm.hibernate3.HibernateTemplate) @bci=128, line=221 (Compiled frame)
- com.lagou.base.proxy.MasterTemplateContainer.access$1(com.lagou.base.proxy.MasterTemplateContainer, org.springframework.orm.hibernate3.HibernateTemplate) @bci=2, line=185 (Interpreted frame)
- com.lagou.base.proxy.MasterTemplateContainer$2.run() @bci=8, line=134 (Interpreted frame)
- java.util.concurrent.ThreadPoolExecutor.runWorker(java.util.concurrent.ThreadPoolExecutor$Worker) @bci=95, line=1145 (Interpreted frame)
- java.util.concurrent.ThreadPoolExecutor$Worker.run() @bci=5, line=615 (Interpreted frame)
- java.lang.Thread.run() @bci=11, line=744 (Interpreted frame)
Thread 24835: (state = BLOCKED)
- java.lang.Thread.sleep(long) @bci=0 (Compiled frame; information may be imprecise)
- com.lagou.base.proxy.MasterTemplateContainer.checkMaster(org.springframework.jdbc.core.JdbcTemplate) @bci=128, line=177 (Compiled frame)
- com.lagou.base.proxy.MasterTemplateContainer.access$0(com.lagou.base.proxy.MasterTemplateContainer, org.springframework.jdbc.core.JdbcTemplate) @bci=2, line=141 (Interpreted frame)
- com.lagou.base.proxy.MasterTemplateContainer$1.run() @bci=8, line=125 (Interpreted frame)
- java.util.concurrent.ThreadPoolExecutor.runWorker(java.util.concurrent.ThreadPoolExecutor$Worker) @bci=95, line=1145 (Interpreted frame)
- java.util.concurrent.ThreadPoolExecutor$Worker.run() @bci=5, line=615 (Interpreted frame)
- java.lang.Thread.run() @bci=11, line=744 (Interpreted frame)我的代码:
private void checkMaster(HibernateTemplate hdao) {
int loopErrors = errorTimes;
int loopSuccess = successTimes;
while(true) {
boolean success = true;
try {
if(hdao == null){
success = false;
continue;
}
success = checkMasterStatusOnce(hdao);//try access database to get the status
} catch (Exception e1) {
logger.error("",e1);
success = false;
}
try {
Thread.sleep(checkInterval);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}中调用该方法
public void check() {
for (final JdbcTemplate jdao : jdbcTemplates) {
threadPoolExecutor.execute(new Runnable(){
public void run() {
checkMaster(jdao);
}
});
}
}发布于 2014-09-16 16:26:32
您说得对,方法Thread中的Thread.sleep的线程状态应该是TIMED_WAITING。
引用权威来源
public static final Thread.State TIMED_WAITING具有指定等待时间的等待线程的线程状态。由于调用具有指定正等待时间的下列方法之一,线程处于计时等待状态:
Thread.sleepObject.waitThread.joinLockSupport.parkNanosLockSupport.parkUntil我在1.6到1.8的范围内测试了几个Java版本(Oracle的实现),所有这些都显示了在Thread.sleep中使用状态TIMED_WAITING报告线程的正确行为。
考虑Thread.sleep()也很重要
…线程不会失去任何监视器的所有权。
因此,由于线程不会失去监视器的所有权,所以它不会重新获取监视器。所以不应该出现在Thread.State.BLOCKED中。
所以,要么使用不同的JVM/JRE实现,要么使用修改过的Thread类,也许它已经在运行时通过仪表进行了修改。无论是哪种情况,你在问题中提供的信息都不足以进一步缩小你的问题范围。
知道您所使用的jstack的哪个版本作为输出有一个与我不同的格式也是有用的。也许是打印错误状态…的工具
https://stackoverflow.com/questions/25865972
复制相似问题