在使用 Spring 的 RestTemplate 与远程服务器通信时,我遇到了一个问题,即我的应用程序的线程已锁定/阻塞。
这是一个阻塞线程的 jstack 信息:
"pool-1-thread-8" prio=10 tid=0x00007fbfd012d800 nid=0x27b1 runnable [0x00007fbfd7dfb000]
java.lang.Thread.State: RUNNABLE
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:129)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:258)
at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
- locked <0x00007fbfe40fe1f8> (a java.io.BufferedInputStream)
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:687)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:632)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1072)
- locked <0x00007fbfe40fe2f0> (a sun.net.www.protocol.http.HttpURLConnection)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:373)
at org.springframework.http.client.SimpleClientHttpResponse.getRawStatusCode(SimpleClientHttpResponse.java:47)
at org.springframework.http.client.AbstractClientHttpResponse.getStatusCode(AbstractClientHttpResponse.java:32)
at org.springframework.web.client.DefaultResponseErrorHandler.getHttpStatusCode(DefaultResponseErrorHandler.java:55)
at org.springframework.web.client.DefaultResponseErrorHandler.hasError(DefaultResponseErrorHandler.java:49)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:489)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:452)
at org.springframework.web.client.RestTemplate.postForObject(RestTemplate.java:302)
at com.xxx.activation.service.action.impl.RestServiceImpl.sendContactRequest(RestServiceImpl.java:37)
at com.xxx.activation.service.action.impl.SendContactRequestAction.perform(SendContactRequestAction.java:125)
at com.xxx.activation.service.action.impl.DefaultStateActionService.doAction(DefaultStateActionService.java:75)
at com.xxx.activation.service.action.impl.ActionProcess$StateActionTask.call(ActionProcess.java:54)
at com.xxx.activation.service.action.impl.ActionProcess$StateActionTask.call(ActionProcess.java:41)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
我该如何解决这个问题?
这与 java.net.URLConnection 的 readTimeout 有关吗?使用Sring的RestTemplate时,底层socket的connectTimeout和readTimeout
的默认值是多少?
提前致谢。