In very ancient days, there used to be a way to "stop" or "kill" a thread, though this is has been deprecated due to it allowing system instability. I noticed though, it's possible to "cancel" a running future. The quotes are there because I don't know how the thread is treated at an OS level.
For my education, What's the difference between canceling a Future, effectively canceling the thread, and stopping the thread? Why is cancelling okay, but stopping/killing a thread in the old days bad?
CANCELLED
, and if it does interrupt any running thread, callsThread#interrupt
. The#interrupt
method will not push aThrowable
(exception) onto the stack of the targetted thread, but instead set a flag for the thread that can be checked viaThread#isInterrupted
. However,Thread#stop
will cause the thread to forcibly end via an arbitrary (and likely unhandled) exception.FutureTask
that implement fromFuture
. This is distinct from the concept ofThread
states.