????????
????HTTP?????????????????????????????????????HTTP????/???????????????????????ε?HTTP????/??????????????????????
????HTTP?????????????????????????????????????????????????????????????ж??????/??????????????????????ù???????????????á?
?????????????HTTP/1.0 ?????????HTTP/1.1?????????????????????ο??????????????????????????????ж?????????????????????????е????????????????????????£?
???????????
?????????????????????HTTP1.1Э????????
????????HTTP??????
??????????????????Connection:close?????????????/???????????????
????????HTTP????????й??????
??????????????????Connection:keep-alive ??Keep-Alive: timeout=60?????????????????????????60????????Ч?????????е?58????????????????????????????Ч???????????????????????60?????????
????????HTTP???????????????
???????????????????Connection:keep-alive????????????Ч??
??????????
???????????????????????????????????????????????????????Connection:keep-alive???????????????????????????????????????connection?????з???????ò???Ч??
????HTTP??????????/????????????????п??????????????з???????????????????HTTP??????????????????????????????????????
??????????????????????????show code????????????????Spring RestTemplate?????apache http client???е??????????????????????????????????????????????????
??????????????Ч???????????Ч???
???????£????????????????????Connection: Keep-Alive??Keep-Alive: timeout=60?? ?????????Connection: Keep-Alive??Keep-Alive: timeout=5??
????## ???????????Ч???60s
????[2017-04-26 14:08:00 DEBUG]  (org.apache.http.wire:?) - http-outgoing-0 >> "POST /adx-api/api/creative/upload HTTP/1.1[ ][ ]"
????[2017-04-26 14:08:00 DEBUG]  (org.apache.http.wire:?) - http-outgoing-0 >> "Accept: application/json?? application/*+json?? text/html?? application/json?? text/javascript[ ][ ]"
????[2017-04-26 14:08:00 DEBUG]  (org.apache.http.wire:?) - http-outgoing-0 >> "Content-Type: application/json;charset=UTF-8[ ][ ]"
????[2017-04-26 14:08:00 DEBUG]  (org.apache.http.wire:?) - http-outgoing-0 >> "User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML?? like Gecko) Chrome/31.0.1650.16 Safari/537.36[ ][ ]"
????[2017-04-26 14:08:00 DEBUG]  (org.apache.http.wire:?) - http-outgoing-0 >> "Accept-Encoding: gzip??deflate[ ][ ]"
????[2017-04-26 14:08:00 DEBUG]  (org.apache.http.wire:?) - http-outgoing-0 >> "Accept-Language: zh-CN[ ][ ]"
????[2017-04-26 14:08:00 DEBUG]  (org.apache.http.wire:?) - http-outgoing-0 >> "Connection: keep-alive[ ][ ]"
????[2017-04-26 14:08:00 DEBUG]  (org.apache.http.wire:?) - http-outgoing-0 >> "Keep-Alive: timeout=60[ ][ ]"
????[2017-04-26 14:08:00 DEBUG]  (org.apache.http.wire:?) - http-outgoing-0 >> "Content-Length: 396[ ][ ]"
????[2017-04-26 14:08:00 DEBUG]  (org.apache.http.wire:?) - http-outgoing-0 >> "Host: bizdomain[ ][ ]"
????[2017-04-26 14:08:00 DEBUG]  (org.apache.http.wire:?) - http-outgoing-0 >> "[ ][ ]"
????[2017-04-26 14:08:00 DEBUG]  (org.apache.http.wire:?) - http-outgoing-0 >> "request data"
????##???????????Ч???5s
????[2017-04-26 14:08:00 DEBUG]  (org.apache.http.wire:?) - http-outgoing-0 << "HTTP/1.1 200 OK[ ][ ]"
????[2017-04-26 14:08:00 DEBUG]  (org.apache.http.wire:?) - http-outgoing-0 << "Date: Wed?? 26 Apr 2017 06:07:58 GMT[ ][ ]"
????[2017-04-26 14:08:00 DEBUG]  (org.apache.http.wire:?) - http-outgoing-0 << "Server: Apache-Coyote/1.1[ ][ ]"
????[2017-04-26 14:08:00 DEBUG]  (org.apache.http.wire:?) - http-outgoing-0 << "Content-Type: text/html;charset=utf-8[ ][ ]"
????[2017-04-26 14:08:00 DEBUG]  (org.apache.http.wire:?) - http-outgoing-0 << "Keep-Alive: timeout=5?? max=100[ ][ ]"
????[2017-04-26 14:08:00 DEBUG]  (org.apache.http.wire:?) - http-outgoing-0 << "Connection: Keep-Alive[ ][ ]"
????[2017-04-26 14:08:00 DEBUG]  (org.apache.http.wire:?) - http-outgoing-0 << "Transfer-Encoding: chunked[ ][ ]"
????[2017-04-26 14:08:00 DEBUG]  (org.apache.http.wire:?) - http-outgoing-0 << "[ ][ ]"
????[2017-04-26 14:08:00 DEBUG]  (org.apache.http.wire:?) - http-outgoing-0 << "63[ ][ ]"
????[2017-04-26 14:08:00 DEBUG]  (org.apache.http.wire:?) - http-outgoing-0 << "response data"
????????????????Ч????????????????????????Ч??????????????????????????????lease???????????Connection expired @ Wed Apr 26 14:08:05???????????????????5s?Ч??????????????????Ч???
????[2017-04-26 14:11:00 DEBUG] (org.apache.http.impl.conn.PoolingHttpClientConnectionManager:?) - Connection request: [route: {}->http://bizdomain:80][total kept alive: 1; route allocated: 1 of 32; total allocated: 1 of 200]
????[2017-04-26 14:11:00 DEBUG] (org.apache.http.impl.conn.CPool:?) - Connection [id:2][route:{}->http://bizdomain:80][state:null] expired @ Wed Apr 26 14:08:05 GMT+08:00 2017
??????????
???????????????????????Ч???????ù????
//org.apache.http.impl.execchain.MainClientExec#execute
......
//?????????lease connection
final HttpClientConnectionmanagedConn = connRequest.get(timeout > 0 ? timeout : 0?? TimeUnit.MILLISECONDS);
......
//??conenction?????ConnectionHolder??
final ConnectionHolder connHolder = new ConnectionHolder(this.log?? this.connManager?? managedConn);
......
// The connection is in or can be brought to a re-usable state.
//??????????????connection?????close??????false
if (reuseStrategy.keepAlive(response?? context)) {
// Set the idle duration of this connection
//???response?????У?keep-alive??timeout?
final long duration = keepAliveStrategy.getKeepAliveDuration(response?? context);
if (this.log.isDebugEnabled()) {
final String s;
if (duration > 0) {
s = "for " + duration + " " + TimeUnit.MILLISECONDS;
} else {
s = "indefinitely";
}
this.log.debug("Connection can be kept alive " + s);
}
//?????Ч???
connHolder.setValidFor(duration?? TimeUnit.MILLISECONDS);
connHolder.markReusable();
} else {
connHolder.markNonReusable();
}
???????????????????????????connHolder.releaseConnection()??????org.apache.http.impl.conn.PoolingHttpClientConnectionManager#releaseConnection??????
@Override
public void releaseConnection(final HttpClientConnection managedConn??
final Object state??final long keepalive?? final TimeUnit tunit) {
Args.notNull(managedConn?? "Managed connection");
synchronized (managedConn) {
final CPoolEntry entry = CPoolProxy.detach(managedConn);
if (entry == null) {
return;
}
final ManagedHttpClientConnection conn = entry.getConnection();
try {
if (conn.isOpen()) {
final TimeUnit effectiveUnit = tunit != null ? tunit : TimeUnit.MILLISECONDS;
entry.setState(state);
//?????Ч???
entry.updateExpiry(keepalive?? effectiveUnit);
}
} finally {
????????????
}
}
}
}
??????????????HTTP??????????????л???????
//org.apache.http.impl.conn.PoolingHttpClientConnectionManager#requestConnection????org.apache.http.pool.AbstractConnPool#lease??
//????getPoolEntryBlocking??????org.apache.http.impl.conn.CPoolEntry#isExpired
@Override
public boolean isExpired(final long now) {
final boolean expired = super.isExpired(now);
if (expired && this.log.isDebugEnabled()) {
//????п?????????
this.log.debug("Connection " + this + " expired @ " + new Date(getExpiry()));
}
return expired;
}
???????????????????Ч????????response???????????????