job-scheduler/src/main/java/org/hawkular/metrics/scheduler/impl/LockManager.java
public void shutdown() {
        try {
            locksExecutor.shutdown();
            locksExecutor.awaitTermination(5, TimeUnit.SECONDS);
            CountDownLatch latch = new CountDownLatch(1);
            activeLocksLock.writeLock().lock();
            Observable.from(activeLocks.entrySet())
                    .map(Map.Entry::getValue)
                    .flatMap(lock -> releaseLock(lock.getName(), lock.getValue())
                            .map(released -> new Lock(lock.getName(), lock.getValue(), lock.getExpiration(), lock
                                    .getRenewalRate(), !released)))
                    .subscribe(
                            lock -> {
                                if (lock.isLocked()) {
                                    logger.infof("Failed to release lock %s", lock.getName());
                                }
                            },
                            t -> {
                                logger.info("There was an error while releasing locks", t);
                                latch.countDown();
                            },
                            latch::countDown
                    );
            latch.await();
            logger.info("Shutdown complete");
        } catch (InterruptedException e) {
            logger.debug("Shutdown was interrupted. Some locks may not have been released but they will still expire.");
        }
    }
public void shutdown() {
        try {
            locksExecutor.shutdown();
            locksExecutor.awaitTermination(5, TimeUnit.SECONDS);
            CountDownLatch latch = new CountDownLatch(1);
            activeLocksLock.writeLock().lock();
            Observable.from(activeLocks.entrySet())
                    .map(Map.Entry::getValue)
                    .flatMap(lock -> releaseLock(lock.getName(), lock.getValue())
                            .map(released -> new Lock(lock.getName(), lock.getValue(), lock.getExpiration(), lock
                                    .getRenewalRate(), !released)))
                    .subscribe(
                            lock -> {
                                if (lock.isLocked()) {
                                    logger.infof("Failed to release lock %s", lock.getName());
                                }
                            },
                            t -> {
                                logger.info("There was an error while releasing locks", t);
                                latch.countDown();
                            },
                            latch::countDown
                    );
            latch.await();
            logger.info("Shutdown complete");
        } catch (InterruptedException e) {
            logger.debug("Shutdown was interrupted. Some locks may not have been released but they will still expire.");
        }
    }
Attempt to release any locks on shutdown so that other clients can obtain those locks without having to wait
for them to expire.