Home

keepAliveTime

keepAliveTime is a configuration parameter used by thread pool implementations to determine how long idle worker threads may remain alive before being terminated. It helps balance responsiveness and resource usage by allowing the pool to shrink during quiet periods while retaining a ready set of threads for bursts of work. The concept is tightly related to the core pool size and the maximum pool size.

In typical thread pool designs, there are core threads and non-core threads. Core threads are kept alive

The value of keepAliveTime is specified with a time unit, such as seconds or minutes. In Java's

Practical guidance: a shorter keepAliveTime reduces idle resource usage but may increase thread churn during bursts;

to
handle
incoming
tasks,
even
when
idle
(unless
core
threads
are
allowed
to
time
out).
Non-core
threads
are
created
as
needed
to
handle
bursts
and
are
eligible
for
termination
after
they
have
been
idle
for
the
keepAliveTime
interval.
If
the
pool
has
more
than
the
core
pool
size,
an
idle
non-core
thread
older
than
keepAliveTime
will
be
terminated.
If
allowCoreThreadTimeOut
is
enabled,
core
threads
can
also
time
out
and
be
terminated
after
the
same
interval.
ThreadPoolExecutor,
for
example,
keepAliveTime
is
configurable
at
construction
and
can
be
adjusted
at
runtime
(typically
via
setKeepAliveTime)
and
is
measured
in
a
TimeUnit.
The
default
is
often
60
seconds
for
non-core
threads.
a
longer
value
reduces
churn
but
retains
more
idle
threads.
Tuning
should
consider
task
duration,
arrival
rate,
and
desired
latency.
If
core
threads
should
also
time
out,
enable
allowCoreThreadTimeOut
and
set
an
appropriate
keepAliveTime
value.