CircuitBreakerImpl implements CircuitBreaker<ET>, CircuitBreaker.ManualModeTask<ET> { protected ScheduledExecutorService getDefaultScheduledExecutorService() { synchronized (CircuitBreakerImpl.class) { if (DEFAULT_SCHEDULED_EXECUTOR_SERVICE == null) { logger.info("Creating default ScheduledExecutorService for CircuitBreaker"); ScheduledThreadPoolExecutor schedulerToUse = new ScheduledThreadPoolExecutor(8); schedulerToUse.setRemoveOnCancelPolicy(true); DEFAULT_SCHEDULED_EXECUTOR_SERVICE = schedulerToUse; } } return DEFAULT_SCHEDULED_EXECUTOR_SERVICE; } CircuitBreakerImpl();  CircuitBreakerImpl(Optional<ScheduledExecutorService> scheduler,
                              Optional<ExecutorService> stateChangeNotificationExecutor,
                              Optional<Integer> maxConsecutiveFailuresAllowed,
                              Optional<Duration> resetTimeout,
                              Optional<Duration> callTimeout,
                              Optional<String> id,
                              Optional<BreakingEventStrategy<ET>> breakingEventStrategy,
                              Optional<BreakingExceptionStrategy> breakingExceptionStrategy); static Builder<E> newBuilder(); static Builder<E> newBuilder(BreakingEventStrategy<E> breakingEventStrategy); @Override ManualModeTask<ET> newManualModeTask(); @Override void throwExceptionIfCircuitBreakerIsOpen(); @Override void handleEvent(ET event); @Override void handleException(Throwable throwable); @Override CircuitBreaker<ET> originatingCircuitBreaker(); @Override CompletableFuture<ET> executeAsyncCall(Supplier<CompletableFuture<ET>> eventFutureSupplier); @Override ET executeBlockingCall(Callable<ET> eventSupplier); @Override CircuitBreakerImpl<ET> onClose(Runnable listener); @Override CircuitBreakerImpl<ET> onHalfOpen(Runnable listener); @Override CircuitBreakerImpl<ET> onOpen(Runnable listener); @Override String getId(); static final String DEFAULT_MAX_CONSECUTIVE_FAILURES_ALLOWED_SYSTEM_PROP_KEY; static final String DEFAULT_RESET_TIMEOUT_SECONDS_SYSTEM_PROP_KEY; static final int DEFAULT_MAX_CONSECUTIVE_FAILURES_ALLOWED; static final long DEFAULT_RESET_TIMEOUT_SECONDS; static final int FALLBACK_DEFAULT_MAX_CONSECUTIVE_FAILURES_ALLOWED; static final long FALLBACK_DEFAULT_RESET_TIMEOUT_SECONDS; static final BreakingEventStrategy<?> DEFAULT_BREAKING_EVENT_STRATEGY; static final BreakingExceptionStrategy DEFAULT_BREAKING_EXCEPTION_STRATEGY; }
@Test public void default_scheduler_has_setRemoveOnCancelPolicy_set_to_true() { ScheduledExecutorService defaultScheduler = new CircuitBreakerImpl<>().getDefaultScheduledExecutorService(); assertThat(defaultScheduler).isInstanceOf(ScheduledThreadPoolExecutor.class); assertThat(((ScheduledThreadPoolExecutor) defaultScheduler).getRemoveOnCancelPolicy()).isTrue(); }