Home

shutdownNow

shutdownNow is a method in the Java standard library, defined by the ExecutorService interface in the java.util.concurrent package. It was introduced to provide a means of attempting an immediate shutdown of an executor, as an alternative to the graceful shutdown provided by shutdown().

When invoked, shutdownNow tries to stop all actively executing tasks and halts the processing of waiting tasks.

The method returns a List<Runnable> containing the tasks that were submitted to the executor but had not

shutdownNow does not guarantee cancellation of tasks that are currently running in a non-cooperative way; it

Compared with shutdown(), which transitions the executor to a state where no new tasks are accepted but

It
does
not
guarantee
that
running
tasks
will
stop
promptly;
it
will
attempt
to
interrupt
their
threads,
and
tasks
may
ignore
the
interruption
or
respond
in
custom
ways.
It
does
not
guarantee
that
all
tasks
will
terminate
immediately.
yet
begun
execution.
Tasks
that
have
already
started
or
completed
will
not
be
in
the
returned
list.
relies
on
cooperative
cancellation.
If
the
security
manager
denies
interruption,
a
SecurityException
may
be
thrown.
After
calling
shutdownNow,
the
executor
is
considered
shut
down
for
new
submissions,
though
already
running
tasks
may
continue
to
completion
if
they
resist
interruption.
running
tasks
are
allowed
to
complete,
shutdownNow
is
intended
for
rapid
termination
when
a
graceful
shutdown
is
not
possible.
Developers
should
handle
InterruptedException
in
tasks
and
check
the
returned
list
to
determine
what
remains
pending.