private synchronized void startScheduler(final long period, final TimeUnit timeUnit) { // let the running task to finish its job. cancelRunningTask(); if (period > 0) { // scheduleWithFixedDelay is used instead of scheduleAtFixedRate because the later can cause a problem // (thread tries to make up for lost time in some situations) final Runnable runnable = lazyRunnable.get(); notNull(runnable); // avoid reject when this method is accessed concurrently. if (!poolInitializer.get().isShutdown()) { LOG.debug("[START] Scheduling thread with period of {} {}. ThreadId: {}", period, timeUnit, Thread.currentThread().getId()); // do not execute immediately. Use period also for initial delay. final long initialDelay = period; future = poolInitializer.get().scheduleWithFixedDelay(runnable, initialDelay, period, timeUnit); } } }
private synchronized void startScheduler(final long period, final TimeUnit timeUnit) { // let the running task to finish its job. cancelRunningTask(); if (period > 0) { // scheduleWithFixedDelay is used instead of scheduleAtFixedRate because the later can cause a problem // (thread tries to make up for lost time in some situations) final Runnable runnable = lazyRunnable.get(); notNull(runnable); // avoid reject when this method is accessed concurrently. if (!poolInitializer.get().isShutdown()) { LOG.debug("[START] Scheduling thread with period of {} {}. ThreadId: {}", period, timeUnit, Thread.currentThread().getId()); // do not execute immediately. Use period also for initial delay. final long initialDelay = period; future = poolInitializer.get().scheduleWithFixedDelay(runnable, initialDelay, period, timeUnit); } } }