这是GC的一些记录 GC Heap History (10 events): Event: 53.954 GC heap before {Heap before GC invocations=4 (full 0): PSYoungGen total 418304K, used 418296K [0x0000000704ab0000, 0x0000000737bb0000, 0x0000000800000000) eden space 386176K, 100% used [0x0000000704ab0000,0x000000071c3d0000,0x000000071c3d0000) from space 32128K, 99% used [0x000000071c3d0000,0x000000071e32e2a0,0x000000071e330000) to space 32128K, 0% used [0x0000000735c50000,0x0000000735c50000,0x0000000737bb0000) ParOldGen total 514752K, used 18851K [0x000000050e000000, 0x000000052d6b0000, 0x0000000704ab0000) object space 514752K, 3% used [0x000000050e000000,0x000000050f268d50,0x000000052d6b0000) PSPermGen total 21248K, used 12383K [0x0000000508e00000, 0x000000050a2c0000, 0x000000050e000000) object space 21248K, 58% used [0x0000000508e00000,0x0000000509a17d00,0x000000050a2c0000) Event: 63.224 GC heap after Heap after GC invocations=4 (full 0): PSYoungGen total 804480K, used 32111K [0x0000000704ab0000, 0x0000000737bb0000, 0x0000000800000000) eden space 772352K, 0% used [0x0000000704ab0000,0x0000000704ab0000,0x0000000733cf0000) from space 32128K, 99% used [0x0000000735c50000,0x0000000737babdf8,0x0000000737bb0000) to space 32128K, 0% used [0x0000000733cf0000,0x0000000733cf0000,0x0000000735c50000) ParOldGen total 514752K, used 19834K [0x000000050e000000, 0x000000052d6b0000, 0x0000000704ab0000) object space 514752K, 3% used [0x000000050e000000,0x000000050f35e868,0x000000052d6b0000) PSPermGen total 21248K, used 12383K [0x0000000508e00000, 0x000000050a2c0000, 0x000000050e000000) object space 21248K, 58% used [0x0000000508e00000,0x0000000509a17d00,0x000000050a2c0000) } Event: 103.359 GC heap before {Heap before GC invocations=5 (full 0): PSYoungGen total 804480K, used 804463K [0x0000000704ab0000, 0x0000000737bb0000, 0x0000000800000000) eden space 772352K, 100% used [0x0000000704ab0000,0x0000000733cf0000,0x0000000733cf0000) from space 32128K, 99% used [0x0000000735c50000,0x0000000737babdf8,0x0000000737bb0000) to space 32128K, 0% used [0x0000000733cf0000,0x0000000733cf0000,0x0000000735c50000) ParOldGen total 514752K, used 19834K [0x000000050e000000, 0x000000052d6b0000, 0x0000000704ab0000) object space 514752K, 3% used [0x000000050e000000,0x000000050f35e868,0x000000052d6b0000) PSPermGen total 21248K, used 12438K [0x0000000508e00000, 0x000000050a2c0000, 0x000000050e000000) object space 21248K, 58% used [0x0000000508e00000,0x0000000509a25bf8,0x000000050a2c0000) Event: 105.014 GC heap after Heap after GC invocations=5 (full 0): PSYoungGen total 804480K, used 32107K [0x0000000704ab0000, 0x0000000768790000, 0x0000000800000000) eden space 772352K, 0% used [0x0000000704ab0000,0x0000000704ab0000,0x0000000733cf0000) from space 32128K, 99% used [0x0000000733cf0000,0x0000000735c4ad60,0x0000000735c50000) to space 45248K, 0% used [0x0000000765b60000,0x0000000765b60000,0x0000000768790000) ParOldGen total 514752K, used 22407K [0x000000050e000000, 0x000000052d6b0000, 0x0000000704ab0000) object space 514752K, 4% used [0x000000050e000000,0x000000050f5e1dd0,0x000000052d6b0000) PSPermGen total 21248K, used 12438K [0x0000000508e00000, 0x000000050a2c0000, 0x000000050e000000) object space 21248K, 58% used [0x0000000508e00000,0x0000000509a25bf8,0x000000050a2c0000) } 内存肯定是足够大的,服务器质量也绝对强悍。就是不知道为什么
去网上找了下源码,发出来 大家看看package org.apache.http.client.protocol;import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.util.ArrayList; import java.util.List;import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.http.Header; import org.apache.http.HttpException; import org.apache.http.HttpHost; import org.apache.http.HttpRequest; import org.apache.http.HttpRequestInterceptor; import org.apache.http.ProtocolException; import org.apache.http.client.CookieStore; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.client.params.HttpClientParams; import org.apache.http.conn.ManagedClientConnection; import org.apache.http.cookie.Cookie; import org.apache.http.cookie.CookieOrigin; import org.apache.http.cookie.CookieSpec; import org.apache.http.cookie.CookieSpecRegistry; import org.apache.http.protocol.HttpContext; import org.apache.http.protocol.ExecutionContext;/*** * Request interceptor that matches cookies available in the current * {@link CookieStore} to the request being executed and generates * corresponding cookierequest headers. * * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a> * * @version $Revision: 673450 $ * * @since 4.0 */ public class RequestAddCookies implements HttpRequestInterceptor { private final Log log = LogFactory.getLog(getClass());
public RequestAddCookies() { super(); }
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { if (request == null) { throw new IllegalArgumentException("HTTP request may not be null"); } if (context == null) { throw new IllegalArgumentException("HTTP context may not be null"); }
// Obtain cookie store CookieStore cookieStore = (CookieStore) context.getAttribute( ClientContext.COOKIE_STORE); if (cookieStore == null) { this.log.info("Cookie store not available in HTTP context"); return; }
// Obtain the registry of cookie specs CookieSpecRegistry registry= (CookieSpecRegistry) context.getAttribute( ClientContext.COOKIESPEC_REGISTRY); if (registry == null) { this.log.info("CookieSpec registry not available in HTTP context"); return; }
// Obtain the target host (required) HttpHost targetHost = (HttpHost) context.getAttribute( ExecutionContext.HTTP_TARGET_HOST); if (targetHost == null) { throw new IllegalStateException("Target host not specified in HTTP context"); }
// Obtain the client connection (required) ManagedClientConnection conn = (ManagedClientConnection) context.getAttribute( ExecutionContext.HTTP_CONNECTION); if (conn == null) { throw new IllegalStateException("Client connection not specified in HTTP context"); } String policy = HttpClientParams.getCookiePolicy(request.getParams()); if (this.log.isDebugEnabled()) { this.log.debug("CookieSpec selected: " + policy); }
URI requestURI; if (request instanceof HttpUriRequest) { requestURI = ((HttpUriRequest) request).getURI(); } else { try { requestURI = new URI(request.getRequestLine().getUri()); } catch (URISyntaxException ex) { throw new ProtocolException("Invalid request URI: " + request.getRequestLine().getUri(), ex); } }
String hostName = targetHost.getHostName(); int port = targetHost.getPort(); if (port < 0) { port = conn.getRemotePort(); }
CookieOrigin cookieOrigin = new CookieOrigin( hostName, port, requestURI.getPath(), conn.isSecure());
// Get an instance of the selected cookie policy CookieSpec cookieSpec = registry.getCookieSpec(policy, request.getParams()); // Get all cookies available in the HTTP state List<Cookie> cookies = new ArrayList<Cookie>(cookieStore.getCookies()); // Find cookies matching the given origin List<Cookie> matchedCookies = new ArrayList<Cookie>(); for (Cookie cookie : cookies) { if (cookieSpec.match(cookie, cookieOrigin)) { if (this.log.isDebugEnabled()) { this.log.debug("Cookie " + cookie + " match " + cookieOrigin); } matchedCookies.add(cookie); } } // Generate Cookie request headers if (!matchedCookies.isEmpty()) { List<Header> headers = cookieSpec.formatCookies(matchedCookies); for (Header header : headers) { request.addHeader(header); } }
int ver = cookieSpec.getVersion(); if (ver > 0) { boolean needVersionHeader = false; for (Cookie cookie : matchedCookies) { if (ver != cookie.getVersion()) { needVersionHeader = true; } } if (needVersionHeader) { Header header = cookieSpec.getVersionHeader(); if (header != null) { // Advertise cookie version support request.addHeader(header); } } }
// Stick the CookieSpec and CookieOrigin instances to the HTTP context // so they could be obtained by the response interceptor context.setAttribute(ClientContext.COOKIE_SPEC, cookieSpec); context.setAttribute(ClientContext.COOKIE_ORIGIN, cookieOrigin); }
GC Heap History (10 events):
Event: 53.954 GC heap before
{Heap before GC invocations=4 (full 0):
PSYoungGen total 418304K, used 418296K [0x0000000704ab0000, 0x0000000737bb0000, 0x0000000800000000)
eden space 386176K, 100% used [0x0000000704ab0000,0x000000071c3d0000,0x000000071c3d0000)
from space 32128K, 99% used [0x000000071c3d0000,0x000000071e32e2a0,0x000000071e330000)
to space 32128K, 0% used [0x0000000735c50000,0x0000000735c50000,0x0000000737bb0000)
ParOldGen total 514752K, used 18851K [0x000000050e000000, 0x000000052d6b0000, 0x0000000704ab0000)
object space 514752K, 3% used [0x000000050e000000,0x000000050f268d50,0x000000052d6b0000)
PSPermGen total 21248K, used 12383K [0x0000000508e00000, 0x000000050a2c0000, 0x000000050e000000)
object space 21248K, 58% used [0x0000000508e00000,0x0000000509a17d00,0x000000050a2c0000)
Event: 63.224 GC heap after
Heap after GC invocations=4 (full 0):
PSYoungGen total 804480K, used 32111K [0x0000000704ab0000, 0x0000000737bb0000, 0x0000000800000000)
eden space 772352K, 0% used [0x0000000704ab0000,0x0000000704ab0000,0x0000000733cf0000)
from space 32128K, 99% used [0x0000000735c50000,0x0000000737babdf8,0x0000000737bb0000)
to space 32128K, 0% used [0x0000000733cf0000,0x0000000733cf0000,0x0000000735c50000)
ParOldGen total 514752K, used 19834K [0x000000050e000000, 0x000000052d6b0000, 0x0000000704ab0000)
object space 514752K, 3% used [0x000000050e000000,0x000000050f35e868,0x000000052d6b0000)
PSPermGen total 21248K, used 12383K [0x0000000508e00000, 0x000000050a2c0000, 0x000000050e000000)
object space 21248K, 58% used [0x0000000508e00000,0x0000000509a17d00,0x000000050a2c0000)
}
Event: 103.359 GC heap before
{Heap before GC invocations=5 (full 0):
PSYoungGen total 804480K, used 804463K [0x0000000704ab0000, 0x0000000737bb0000, 0x0000000800000000)
eden space 772352K, 100% used [0x0000000704ab0000,0x0000000733cf0000,0x0000000733cf0000)
from space 32128K, 99% used [0x0000000735c50000,0x0000000737babdf8,0x0000000737bb0000)
to space 32128K, 0% used [0x0000000733cf0000,0x0000000733cf0000,0x0000000735c50000)
ParOldGen total 514752K, used 19834K [0x000000050e000000, 0x000000052d6b0000, 0x0000000704ab0000)
object space 514752K, 3% used [0x000000050e000000,0x000000050f35e868,0x000000052d6b0000)
PSPermGen total 21248K, used 12438K [0x0000000508e00000, 0x000000050a2c0000, 0x000000050e000000)
object space 21248K, 58% used [0x0000000508e00000,0x0000000509a25bf8,0x000000050a2c0000)
Event: 105.014 GC heap after
Heap after GC invocations=5 (full 0):
PSYoungGen total 804480K, used 32107K [0x0000000704ab0000, 0x0000000768790000, 0x0000000800000000)
eden space 772352K, 0% used [0x0000000704ab0000,0x0000000704ab0000,0x0000000733cf0000)
from space 32128K, 99% used [0x0000000733cf0000,0x0000000735c4ad60,0x0000000735c50000)
to space 45248K, 0% used [0x0000000765b60000,0x0000000765b60000,0x0000000768790000)
ParOldGen total 514752K, used 22407K [0x000000050e000000, 0x000000052d6b0000, 0x0000000704ab0000)
object space 514752K, 4% used [0x000000050e000000,0x000000050f5e1dd0,0x000000052d6b0000)
PSPermGen total 21248K, used 12438K [0x0000000508e00000, 0x000000050a2c0000, 0x000000050e000000)
object space 21248K, 58% used [0x0000000508e00000,0x0000000509a25bf8,0x000000050a2c0000)
}
内存肯定是足够大的,服务器质量也绝对强悍。就是不知道为什么
# J org.apache.http.client.protocol.RequestAddCookies.process(Lorg/apache/http/HttpRequest;Lorg/apache/http/protocol/HttpContext;)V这个方法崩溃的,检查下这个方法都干了啥。
org.apache.http.client.protocol.RequestAddCookies.process
然后在那周围查错,或者你把那部分代码发上来大家一起看
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.Header;
import org.apache.http.HttpException;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpRequestInterceptor;
import org.apache.http.ProtocolException;
import org.apache.http.client.CookieStore;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.params.HttpClientParams;
import org.apache.http.conn.ManagedClientConnection;
import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.CookieSpec;
import org.apache.http.cookie.CookieSpecRegistry;
import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.ExecutionContext;/***
* Request interceptor that matches cookies available in the current
* {@link CookieStore} to the request being executed and generates
* corresponding cookierequest headers.
*
* @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
*
* @version $Revision: 673450 $
*
* @since 4.0
*/
public class RequestAddCookies implements HttpRequestInterceptor { private final Log log = LogFactory.getLog(getClass());
public RequestAddCookies() {
super();
}
public void process(final HttpRequest request, final HttpContext context)
throws HttpException, IOException {
if (request == null) {
throw new IllegalArgumentException("HTTP request may not be null");
}
if (context == null) {
throw new IllegalArgumentException("HTTP context may not be null");
}
// Obtain cookie store
CookieStore cookieStore = (CookieStore) context.getAttribute(
ClientContext.COOKIE_STORE);
if (cookieStore == null) {
this.log.info("Cookie store not available in HTTP context");
return;
}
// Obtain the registry of cookie specs
CookieSpecRegistry registry= (CookieSpecRegistry) context.getAttribute(
ClientContext.COOKIESPEC_REGISTRY);
if (registry == null) {
this.log.info("CookieSpec registry not available in HTTP context");
return;
}
// Obtain the target host (required)
HttpHost targetHost = (HttpHost) context.getAttribute(
ExecutionContext.HTTP_TARGET_HOST);
if (targetHost == null) {
throw new IllegalStateException("Target host not specified in HTTP context");
}
// Obtain the client connection (required)
ManagedClientConnection conn = (ManagedClientConnection) context.getAttribute(
ExecutionContext.HTTP_CONNECTION);
if (conn == null) {
throw new IllegalStateException("Client connection not specified in HTTP context");
} String policy = HttpClientParams.getCookiePolicy(request.getParams());
if (this.log.isDebugEnabled()) {
this.log.debug("CookieSpec selected: " + policy);
}
URI requestURI;
if (request instanceof HttpUriRequest) {
requestURI = ((HttpUriRequest) request).getURI();
} else {
try {
requestURI = new URI(request.getRequestLine().getUri());
} catch (URISyntaxException ex) {
throw new ProtocolException("Invalid request URI: " +
request.getRequestLine().getUri(), ex);
}
}
String hostName = targetHost.getHostName();
int port = targetHost.getPort();
if (port < 0) {
port = conn.getRemotePort();
}
CookieOrigin cookieOrigin = new CookieOrigin(
hostName,
port,
requestURI.getPath(),
conn.isSecure());
// Get an instance of the selected cookie policy
CookieSpec cookieSpec = registry.getCookieSpec(policy, request.getParams());
// Get all cookies available in the HTTP state
List<Cookie> cookies = new ArrayList<Cookie>(cookieStore.getCookies());
// Find cookies matching the given origin
List<Cookie> matchedCookies = new ArrayList<Cookie>();
for (Cookie cookie : cookies) {
if (cookieSpec.match(cookie, cookieOrigin)) {
if (this.log.isDebugEnabled()) {
this.log.debug("Cookie " + cookie + " match " + cookieOrigin);
}
matchedCookies.add(cookie);
}
}
// Generate Cookie request headers
if (!matchedCookies.isEmpty()) {
List<Header> headers = cookieSpec.formatCookies(matchedCookies);
for (Header header : headers) {
request.addHeader(header);
}
}
int ver = cookieSpec.getVersion();
if (ver > 0) {
boolean needVersionHeader = false;
for (Cookie cookie : matchedCookies) {
if (ver != cookie.getVersion()) {
needVersionHeader = true;
}
} if (needVersionHeader) {
Header header = cookieSpec.getVersionHeader();
if (header != null) {
// Advertise cookie version support
request.addHeader(header);
}
}
}
// Stick the CookieSpec and CookieOrigin instances to the HTTP context
// so they could be obtained by the response interceptor
context.setAttribute(ClientContext.COOKIE_SPEC, cookieSpec);
context.setAttribute(ClientContext.COOKIE_ORIGIN, cookieOrigin);
}
}
②httpclient是4.2.6版本的,单个线程所有访问共享同一个httpclient,但是每次访问使用不同的HttpGet,get由垃圾回收器自主回收
③每个连接使用随机生成的cookie (满足服务器的要求),保持连接,编码同服务器
④使用了sun_jdk7u44之后运行五天没问题,使用自编译openJDK运行时报错。未能探知错误原因。希望大神们传传,看看这问题究竟是出在那儿的
貌似这是是JIT compiler的一个bug,openjdk在2013年8月修复了这个问题,看你的openjdk的版本是在2月份左右编译的,可能还没修复这个bug吧。更新下openjdk的版本看看。
附几个老外的链接,貌似最后的解释都是JIT的问题。http://mail-archives.apache.org/mod_mbox/hc-httpclient-users/201304.mbox/%3C1365579901.16348.12.camel@ubuntu%3Ehttp://bugs.java.com/view_bug.do?bug_id=8021898
这个问题的出现有很强的几率性的。我用jdk1.7u22的时候也出现了这样的问题。但是平均几率很低。