PriorityQueueEmailSchedulerService implements EmailSchedulerService { @PreDestroy protected void cleanUp() throws Exception { log.info("Closing EmailScheduler"); try { executor.shutdownNow(); schedulerLock.lock(); try { this.serviceStatus = ServiceStatus.CLOSING; } finally { schedulerLock.unlock(); } log.debug("EMAIL SCHEDULER -- Closing PriorityQueueManager"); priorityQueueManager.close(); if (nonNull(resumer)) { log.debug("EMAIL SCHEDULER -- Closing Resumer"); resumer.close(); } log.debug("EMAIL SCHEDULER -- Closing Consumer"); consumer.close(); } catch (Exception e) { log.warn("An issue occurred while stopping EmailScheduler, it should be due to a thread interruption.", e); } finally { this.serviceStatus = ServiceStatus.CLOSED; } log.info("Closed EmailScheduler"); } @Autowired  PriorityQueueEmailSchedulerService(
            final EmailService emailService,
            final EmailSchedulerProperties emailSchedulerProperties,
            final Optional<PersistenceService> persistenceServiceOptional,
            final EmailLogRenderer emailLogRenderer); @Override @Async void schedule(@NonNull final Email mimeEmail, final int desiredPriorityLevel); @Override @Async void schedule(@NonNull final Email mimeEmail, @NonNull final OffsetDateTime scheduledDateTime, final int desiredPriorityLevel); @Override @Async void schedule(@NonNull final Email mimeEmail, final int desiredPriorityLevel, @NonNull final String template,
                         @NonNull final Map<String, Object> modelObject, final InlinePicture... inlinePictures); @Override @Async void schedule(@NonNull final Email mimeEmail, @NonNull final OffsetDateTime scheduledDateTime, final int desiredPriorityLevel,
                         @NonNull final String template, @NonNull final Map<String, Object> modelObject, final InlinePicture... inlinePictures);  }
@Test public void shouldClose() throws Exception { PriorityQueueEmailSchedulerService priorityQueueSchedulerService = scheduler(1); priorityQueueSchedulerService.cleanUp(); Thread.sleep(twoSecondsInMillis()); given(priorityQueueSchedulerService.status()).assertThat(CoreMatchers.is(ServiceStatus.CLOSED)); }