@Override public void backgroundProcess() { // This method gets called once a second. backgroundProcessCount++; if (backgroundProcessCount >= processPeriod) { backgroundProcessCount = 0; long now = System.currentTimeMillis(); Iterator<WsRemoteEndpointImplServer> iter = endpoints.iterator(); while (iter.hasNext()) { WsRemoteEndpointImplServer endpoint = iter.next(); if (endpoint.getTimeoutExpiry() < now) { // Background thread, not the thread that triggered the // write so no need to use a dispatch endpoint.onTimeout(false); } else { // Endpoints are ordered by timeout expiry so if this point // is reached there is no need to check the remaining // endpoints break; } } } }