private void cleanupNonces() { long now = System.currentTimeMillis() / 1000; // don't clean out the NONCES for each request, this would cause the service to be constantly locked on this // loop under load. One second is small enough that cleaning up does not become too expensive. // Also see SECOAUTH-180 for reasons this class was refactored. if (now - lastCleaned > 1) { Iterator<NonceEntry> iterator = NONCES.iterator(); while (iterator.hasNext()) { // the nonces are already sorted, so simply iterate and remove until the first nonce within the validity // window. NonceEntry nextNonce = iterator.next(); long difference = now - nextNonce.timestamp; if (difference > getValidityWindowSeconds()) { iterator.remove(); } else { break; } } // keep track of when cleanupNonces last ran lastCleaned = now; } }