A scheduled executor is built with a core pool size of 0, so its delayed tasks lack a thread

tx0/java:zero-core-threadsdefaultwarningbug, concurrency

What it finds

new ScheduledThreadPoolExecutor(0) or Executors.newScheduledThreadPool(0) makes a scheduled pool with no core threads. Such a pool never keeps a thread around for its delayed tasks, and depending on the runtime they run late, busy-wait or not at all. A scheduled pool needs at least one core thread.

From the rule's source, zero_core_threads.rs.

Example from the rule's tests
import java.util.concurrent.Executors;import java.util.concurrent.ScheduledExecutorService;import java.util.concurrent.ScheduledThreadPoolExecutor; class Timers {  ScheduledExecutorService a = new ScheduledThreadPoolExecutor(0);tx0 reports: the scheduled pool has no core threads  ScheduledExecutorService b = Executors.newScheduledThreadPool(0);tx0 reports: the scheduled pool has no core threads  ScheduledExecutorService c = Executors.newScheduledThreadPool(1);}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:

tx0.toml
[rules]
"tx0/java:zero-core-threads" = "off"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/java:zero-core-threads] reason="..."

tx0 explain tx0/java:zero-core-threads shows the same in the terminal. Found a false positive? Report it.