我在多个worker中使用Apache HTTP客户端,看起来有某种竞争条件(stacktrace就在最后)。我很困惑,谷歌搜索堆栈跟踪没有提供任何提示(尚未)。在Linux上使用Java 1.7.0-b147 64位。
SSLSocket
?修改 也许没用,但是调用代码就像:
public String call() {
HttpUriRequest request = new HttpGet(aUrl);
HttpResponse response = httpClient.execute(request);
StatusLine statusLine = response.getStatusLine();
return EntityUtils.toString(response.getEntity());
}
其中httpClient与所有可调用对象共享。
堆栈跟踪:
java.lang.NullPointerException
at sun.security.ssl.SSLSocketImpl.getEnabledCipherSuites(SSLSocketImpl.java:2320)
at javax.net.ssl.SSLSocket.getSSLParameters(SSLSocket.java:614)
at sun.security.ssl.SSLSocketImpl.getSSLParameters(SSLSocketImpl.java:2406)
at sun.security.ssl.SSLAlgorithmConstraints.<init>(SSLAlgorithmConstraints.java:65)
at sun.security.ssl.Handshaker.init(Handshaker.java:236)
at sun.security.ssl.Handshaker.<init>(Handshaker.java:191)
at sun.security.ssl.ClientHandshaker.<init>(ClientHandshaker.java:104)
at sun.security.ssl.SSLSocketImpl.initHandshaker(SSLSocketImpl.java:1217)
at sun.security.ssl.SSLSocketImpl.doneConnect(SSLSocketImpl.java:634)
at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:608)
at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:414)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:180)
at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:294)
at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:643)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:479)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:906)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:805)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:784)
答案 0 :(得分:2)
这是一个JDK问题。运行JDK 1.7.0_u4时遇到此问题,升级到JDK 1.7.0_u25后解决了。