목차

Apache Http Client

Connection 갯수

HttpClient httpClient = HttpClientBuilder.create().useSystemProperties()
    .setMaxConnTotal([최대 커넥션 갯수])
    .setMaxConnPerRoute([IP/domain name당 최대 커넥션 갯수])
    ....

Connection/Socket Timeout

Evict Idle Connections

HttpClient httpClient = HttpClientBuilder.create().
      .evictIdleConnections(2000L, TimeUnit.MILLISECONDS)
      ....
      .build();
Please note this method has no effect if the instance of HttpClient is configuted to use a shared connection manager.
Please note this method may not be used when the instance of HttpClient is created inside an EJB container.

Request Character Encoding

일반

HttpProtocolParams.setContentCharset(httpParams, "UTF-8");

POST 요청시 URL Encoded Form

UrlEncodedFormEntity 클래스 생성자에서 문자 인코딩 지정

HttpPost post = new HttpPost("http://....");
List<NameValuePair> params = new ArrayList<>();
 
params.add(new BasicNameValuePair("paramName", "param value"));
// params...
 
post.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));

HttpAsyncClient

Stale Check

> HTTP specification permits both the client and the server to terminate a persistent (keep-alive) connection at any time without notice to the counterpart, thus rendering the connection invalid or stale. By default HttpClient performs a check, just prior to executing a request, to determine if the active connection is stale. The cost of this operation is about 15-30 ms, depending on the JRE used. Disabling stale connection check may result in slight performance improvement, especially for small payload responses, at the risk of getting an I/O error when executing a request over a connection that has been closed at the server side.


See the http.connection.stalecheck parameter documentation for more information.

참조