/** * Since we allow resetting the timer (shutting down the thread) we need to lazily re-start it if it starts being used again. * <p> * This does the lazy initialization and start of the thread in a thread-safe manner while having little cost the rest of the time. */ protected void startThreadIfNeeded() { // create and start thread if one doesn't exist while (executor.get() == null || ! executor.get().isInitialized()) { if (executor.compareAndSet(null, new ScheduledExecutor())) { // initialize the executor that we 'won' setting executor.get().initialize(); } } }
/** * Since we allow resetting the timer (shutting down the thread) we need to lazily re-start it if it starts being used again. * <p> * This does the lazy initialization and start of the thread in a thread-safe manner while having little cost the rest of the time. */ protected void startThreadIfNeeded() { // create and start thread if one doesn't exist while (executor.get() == null || ! executor.get().isInitialized()) { if (executor.compareAndSet(null, new ScheduledExecutor())) { // initialize the executor that we 'won' setting executor.get().initialize(); } } }