HttpClient 로 인 한 스 레 드 가 너무 많아 서 FullGc 에 문제 가 생 겼 습 니 다.
3795 단어 HttpClient스 레 드FullGc
CloseableHttpClient httpClient = HttpClients.custom()
.setConnectionManager(connectionManager)
.setMaxConnTotal(400)
.setMaxConnPerRoute(150)
.evictExpiredConnections()
.build();
evictExpiredConnections 이 설정 역할:정시 스 레 드 를 설정 하고 유 휴 연결 을 정리 합 니 다.이 정시 시간 을 keep alive timeout 시간의 절반 으로 설정 하여 시간 초과 전 회수 할 수 있 습 니 다.
http Client 대상 마다 독립 된 타 이 밍 스 레 드 가 있 습 니 다.
이렇게 하면 http Client 대상 이 많 으 면 위의 그림 에 스 레 드 가 너무 많 습 니 다.
원본 코드 에서 evictExpired Connections 를 설정 하면 다음 논리 가 있 습 니 다.
List<Closeable> closeablesCopy = closeables != null ? new ArrayList<Closeable>(closeables) : null;
if (!this.connManagerShared) {
if (closeablesCopy == null) {
closeablesCopy = new ArrayList<Closeable>(1);
}
final HttpClientConnectionManager cm = connManagerCopy;
if (evictExpiredConnections || evictIdleConnections) {
final IdleConnectionEvictor connectionEvictor = new IdleConnectionEvictor(cm,
maxIdleTime > 0 ? maxIdleTime : 10, maxIdleTimeUnit != null ? maxIdleTimeUnit : TimeUnit.SECONDS,
maxIdleTime, maxIdleTimeUnit);
closeablesCopy.add(new Closeable() {
@Override
public void close() throws IOException {
connectionEvictor.shutdown();
try {
connectionEvictor.awaitTermination(1L, TimeUnit.SECONDS);
} catch (final InterruptedException interrupted) {
Thread.currentThread().interrupt();
}
}
});
connectionEvictor.start();
}
closeablesCopy.add(new Closeable() {
@Override
public void close() throws IOException {
cm.shutdown();
}
});
}
IdleConnection Evictor 대상 은?
public final class IdleConnectionEvictor {
private final HttpClientConnectionManager connectionManager;
private final ThreadFactory threadFactory;
private final Thread thread;
private final long sleepTimeMs;
private final long maxIdleTimeMs;
private volatile Exception exception;
public IdleConnectionEvictor(
final HttpClientConnectionManager connectionManager,
final ThreadFactory threadFactory,
final long sleepTime, final TimeUnit sleepTimeUnit,
final long maxIdleTime, final TimeUnit maxIdleTimeUnit) {
this.connectionManager = Args.notNull(connectionManager, "Connection manager");
this.threadFactory = threadFactory != null ? threadFactory : new DefaultThreadFactory();
this.sleepTimeMs = sleepTimeUnit != null ? sleepTimeUnit.toMillis(sleepTime) : sleepTime;
this.maxIdleTimeMs = maxIdleTimeUnit != null ? maxIdleTimeUnit.toMillis(maxIdleTime) : maxIdleTime;
this.thread = this.threadFactory.newThread(new Runnable() {
@Override
public void run() {
try {
while (!Thread.currentThread().isInterrupted()) {
Thread.sleep(sleepTimeMs);
connectionManager.closeExpiredConnections();
if (maxIdleTimeMs > 0) {
connectionManager.closeIdleConnections(maxIdleTimeMs, TimeUnit.MILLISECONDS);
}
}
} catch (final Exception ex) {
exception = ex;
}
}
});
}
스 레 드 가 나타 날 수 있 습 니 다.이 스 레 드 안 에는 시간 이 초과 되 어 사용 하지 않 는 유 휴 링크 를 닫 는 것 입 니 다.HttpClient 로 인 한 스 레 드 가 너무 많아 서 FullGC 에 문제 가 생 긴 다 는 글 을 소개 합 니 다.HttpClient 로 인 한 스 레 드 가 너무 많아 서 FullGC 내용 을 검색 하거나 아래 의 관련 글 을 계속 찾 아 보 세 요.앞으로 많이 응원 해 주세요!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
HttpClient에서 웹 페이지를 캡처하는 두 가지 방법1. NodeFilter를 이용하여 웹 페이지를 분석한다. 1. Parser a를 생성한다. url을 통해 인터넷의 웹 페이지 b를 추출한다. 로컬 웹 파일을 추출하여 파일을 읽고 웹 파일을 문자열로 전환한다. 2....
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.