ScheduledThreadPoolExecutor with corePoolSize = 0 causes 100% load on one processor core

The following is the configuration for ScheduledThreadPoolExecutor , which runs a simple task every five seconds:

 int corePoolSize = 0; ScheduledExecutorService executor = new ScheduledThreadPoolExecutor(corePoolSize); Runnable task = () -> System.out.println("XXX"); executor.scheduleAtFixedRate(task, 5, 5, TimeUnit.SECONDS); 

In Oracle JRE 1.8.0_66 there is one thread created by ScheduledThreadPoolExecutor that constantly causes 100% load on one CPU core. When examining a stream dump, the following stacktrace command is displayed:

 "pool-1-thread-1" - Thread t@10 java.lang.Thread.State: RUNNABLE at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.poll(ScheduledThreadPoolExecutor.java:809) at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1066) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1127) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) 

With corePoolSize = 1 , there is still one thread in the pool. However, the thread is generally always in TIMED_WAITING state and, therefore, inactive.

Is the behavior of a ScheduledThreadPoolExecutor with corePoolSize = 0 known function, an unspecified incorrect configuration, or even an error?

+7
java performance
source share
1 answer

It looks like you ended up in JDK-8129861 , which has been fixed in Java 9. It can also be associated with JDK-8022642 .

+8
source share

All Articles