Home

setCorePoolSize

setCorePoolSize is a method of ThreadPoolExecutor that sets the core pool size, the minimum number of threads that are kept alive in the pool even when idle. The value must be between 0 and maximumPoolSize; passing a value outside this range results in IllegalArgumentException.

In operation, the core pool size defines the baseline level of concurrency. If you increase corePoolSize, the

Core threads are kept alive to handle incoming tasks, even when idle, unless a configuration option allows

The keepAliveTime parameter governs how long threads beyond the core pool size may remain idle before being

Usage notes: adjusting the core pool size can impact performance and resource usage. Changes take effect as

pool
will
create
additional
core
threads
as
needed
to
reach
the
new
size,
up
to
the
maximumPoolSize,
to
help
execute
queued
tasks
more
promptly.
If
you
decrease
corePoolSize,
the
pool
will
reduce
the
number
of
core
threads
by
terminating
excess
idle
core
threads
until
the
current
core
pool
size
matches
the
new
value;
active,
non-idle
threads
are
not
interrupted.
their
timeout.
Specifically,
core
threads
are
normally
not
terminated
due
to
idleness,
unless
allowCoreThreadTimeOut
is
set
to
true.
When
allowCoreThreadTimeOut
is
enabled,
core
threads
may
time
out
and
terminate
after
a
period
of
inactivity,
similar
to
non-core
threads
governed
by
keepAliveTime.
terminated;
core
threads
follow
that
rule
only
if
allowCoreThreadTimeOut
is
enabled.
setCorePoolSize
therefore
provides
a
dynamic
way
to
adjust
the
pool’s
baseline
level
of
concurrency
in
response
to
workload
changes,
influencing
how
many
tasks
can
be
handled
in
parallel
and
how
aggressively
idle
threads
are
managed.
the
pool
decides
to
create
or
terminate
workers,
and
do
not
forcibly
interrupt
currently
executing
tasks.