spring-framework
spring-framework copied to clipboard
When we change the system time to past(say 1 hour before), the ScheduledThreadPoolExecutor starts consuming more CPU (around 95-100%).)
Affects: <Spring Framework version>
Below is the code :
final ThreadFactory threadFactory = new ThreadFactoryBuilder()
.setNameFormat("XXX_THREAD")
.setDaemon(true)
.build();
// Intentionally 1 thread
ScheduledThreadPoolExecutor scheduledExecutor = new ScheduledThreadPoolExecutor(1, threadFactory);
scheduledExecutor.setContinueExistingPeriodicTasksAfterShutdownPolicy(false);
scheduledExecutor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
scheduledExecutor.setRemoveOnCancelPolicy(true);
scheduledExecutor.setRejectedExecutionHandler(new DiscardPolicy());
return scheduledExecutor;
scheduledExecutor.scheduleWithFixedDelay(this::runUpdateJob, 1, 1, TimeUnit.SECONDS);
The moment we change the system time to past (say 1 hour before current time), it starts affecting CPU resources(around 95%). The similar thing could happen during Daylight Saving also where time shifts to 1 hour past. Although, its gets normal when the past time elapsed.
Using JDK 1.8.0_202