问题表现
某定时任务过一段时间死掉,不再输出任务日志。
分析
估计不是线程被干死,一般是活儿一直干不完,在等资源啥的。
过程
jstack 2476|grep Scheduler -A 30
发现大部分线程时起时停,但其中一个一直Running。
“myScheduler-9” #29 prio=5 os_prio=0 tid=0x00007fc52cdd3000 nid=0xa9a runnable [0x00007fc5328a6000] …at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:973) – locked <0x00000006cdb2f4a8> (a java.lang.Object) at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375) – locked <0x00000006cdb2f4b8> (a java.lang.Object)
度娘说“SSLSocketImpl.java:973”:
https://blog.csdn.net/liuxiang87/article/details/53736095
等了15分钟,依然是:
“myScheduler-9” #29 prio=5 os_prio=0 tid=0x00007fc52cdd3000 nid=0xa9a runnable [0x00007fc5328a6000] …at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:973) – locked <0x00000006cdb2f4a8> (a java.lang.Object) at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375) – locked <0x00000006cdb2f4b8> (a java.lang.Object)
好吧,凶手就是你。
看代码,确认过眼神,找到对的人。
总结
HttpClient的坑,就不能设个默认值,还无限等待,情痴啊!
一言不合贴代码:
private static final int MAX_SOKET_TIMEOUT =8000;
private static final int MAX_CONNECTION_TIMEOUT = 8000;private static final RequestConfig REQCONFIG = RequestConfig.custom()
.setSocketTimeout(MAX_SOKET_TIMEOUT) .setConnectTimeout(MAX_CONNECTION_TIMEOUT) .build();CloseableHttpClient httpClient = HttpClients.custom().setDefaultRequestConfig(REQCONFIG).build();