@Override
    public void run() {
        logger.config("Initializing...");
        running = true;
        runLoop:
        while (running) {
            synchronized (this) {
                while (timeouts.isEmpty()) {
                    logger.finest("Waiting for timeout");
                    // Check whether someone asked us to shutdown
                    // If its the case, and as the queue is empty
                    // we are free to break from the main loop and
                    // call shutdown();
                    if (!running) {
                        break runLoop;
                    }
                    try {
                        this.wait();
                    } catch (InterruptedException ie) {
                        logger.log(Level.INFO, "TimeoutWorker lock interrupted on empty container", ie);
                    }
                }
                // At least one timeout was added, loop until timeouts are empty
                while (!timeouts.isEmpty()) {
                    updateCurrentTimeout();
                    // It could be the case that while getting the next time to
                    // wait on, all timeouts have been removed, if this is the
                    // case, break on waiting, otherwise the thread is stuck on
                    // waiting forever
                    if (timeouts.isEmpty()) {
                        break;
                    }
                    try {
                        logger.log(Level.FINEST, "Waiting at {0} until: {1}",
                                new Object[]{System.currentTimeMillis(),
                                    System.currentTimeMillis() + waitTime});
                        this.wait(waitTime);
                    } catch (InterruptedException ie) {
                        logger.log(Level.INFO, "TimeoutWorker lock interrupted while waiting on timeout", ie);
                    }
                    // Here, either the timeout expired or the lock was notified
                    // due to at least one new timeout being added
                    if (!running) {
                        break runLoop;
                    }
                }
                logger.finest("Out of timeoutWait loop, no more timeouts");
            }
        }
        shutdown();
    }