public boolean shouldTrip(Throwable cause) { if (isExceptionIgnorable(cause)) return false; // if Exception is of specified type, and window conditions exist, // keep circuit open unless exception threshold has passed if (hasWindowConditions()) { Long currentRequestCount = -1L; long numberOfErrorsAfter; synchronized (modificationLock) { errorTimes.add(System.currentTimeMillis()); requestCounts.add(requestCounter.sample()[0]); // calculates time for which we remove any errors before final long removeTimeBeforeMillis = System.currentTimeMillis() - windowMillis; final int numberOfErrorsBefore = this.errorTimes.size(); removeErrorsPriorToCutoffTime(numberOfErrorsBefore, removeTimeBeforeMillis); numberOfErrorsAfter = this.errorTimes.size(); currentRequestCount = this.requestCounts.get(requestCounts.size() - 1); } long windowRequests = (currentRequestCount - previousRequestHighWaterMark); // Trip if the number of errors over the total of requests over the same period // is over the percentage limit. return windowRequests >= requestThreshold && (((double) numberOfErrorsAfter / (double) windowRequests) * 100d >= percent); } return true; }