<beanid="memcachedClient"class="net.spy.memcached.spring.MemcachedClientFactoryBean"> …… <propertyname="opTimeout"value="1000"/>操做超時時間是1秒,若是不設置的話,默認是 DEFAULT_OPERATION_TIMEOUT,即2.5秒 <propertyname="timeoutExceptionThreshold"value="1998"/>設置超時次數上限是1998次,默認是DEFAULT_MAX_TIMEOUTEXCEPTION_THRESHOLD,即998次 …… </bean>
|
MemcachedConnection.java
|
private final int timeoutExceptionThreshold;
……
timeoutExceptionThreshold = f.getTimeoutExceptionThreshold();
……
|
/**
* MemcachedClient calls this method to handle IO over the connections.
*/
public void handleIO() throws IOException {
……
// see if any connections blew up with large number of timeouts
for (SelectionKey sk : selector.keys()) {
MemcachedNode mn = (MemcachedNode) sk.attachment();
if (mn.getContinuousTimeout() > timeoutExceptionThreshold) {//檢查一下
getLogger().warn("%s exceeded continuous timeout threshold", sk);
lostConnection(mn);//斷開鏈接,放入重連隊列
}
}
if (!shutDown && !reconnectQueue.isEmpty()) {
attemptReconnects();//從新鏈接
}
// rehash any operations that are in retry state
redistributeOperations(retryOps);//
retryOps.clear();
|
若是配置文件也沒配 timeoutExceptionThreshold ,初始化時也沒傳這個參數, 那麼 DefaultConnectionFactory 就取默認值 DEFAULT_MAX_TIMEOUTEXCEPTION_THRESHOLD,即998次(anyway,也許是1000次)! |
DefaultConnectionFactory.java |
/**
* Maximum number + 2 of timeout exception for shutdown connection.
*/
public static final int DEFAULT_MAX_TIMEOUTEXCEPTION_THRESHOLD = 998;
|
DefaultConnectionFactory.java |
public int getTimeoutExceptionThreshold() {
return DEFAULT_MAX_TIMEOUTEXCEPTION_THRESHOLD;
}
|
TCPMemcachedNodeImpl.java
|
// operation Future.get timeout counter
private final AtomicInteger continuousTimeout = new AtomicInteger(0);
……
public void setContinuousTimeout(boolean timedOut) {
if (timedOut && isActive()) {
continuousTimeout.incrementAndGet();
} else {
continuousTimeout.set(0);
}
}
|
MemcachedConnection.java |
/**
* helper method: increase timeout count on node attached to this op.
*
* @param op
*/
public static void opTimedOut(Operation op) {
MemcachedConnection.setTimeout(op, true);
}
|