Scheduled Executor With Zero Core Threads
ID |
java.executor_zero_core_threads |
Severity |
high |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Reliability |
Language |
Java |
Tags |
reliability |
Description
Reports a java.util.concurrent.ScheduledThreadPoolExecutor whose corePoolSize is set to the
literal 0, either as the constructor’s first argument or through a later
setCorePoolSize(0) call.
Only the literal 0 is matched; a variable or computed size is not flagged. A plain
ThreadPoolExecutor is out of scope — a zero core size there is a legitimate "grow on demand"
configuration.
Rationale
A ScheduledThreadPoolExecutor’s pool is sized by `corePoolSize alone, unlike a general
ThreadPoolExecutor, which can also grow up to a separate maximum. With corePoolSize at
zero, the executor has no threads at all: every task submitted to it is accepted without error
and simply never runs.
ScheduledThreadPoolExecutor scheduler = new ScheduledThreadPoolExecutor(0);
scheduler.scheduleAtFixedRate(this::flushBuffer, 0, 5, TimeUnit.SECONDS); // never executes