Inside the main
method you are invoking run()
on your Thread
so you never start a new Thread
but instead run its code within the initial main
thread. So invoking interrupt
on the Thread
instance you never have started will not interrupt the main
thread which is actually executing the code.
The same error repeats when you submit
a Thread
instance to an Executor
. The executor will execute the run
method of the Thread
instance because Thread
implements Runnable
but the Executor
will do so within its own managed Thread
but not within the Thread
represented by the instance you have created but never started.
So again, invoking interrupt
on the Thread
instance you never have started will not interrupt the thread actually executing the code.
Generally you should not mix Thread
and Executor
usage. Decide for one way, dealing with Thread
s manually or using ExecutorSevice
s.
And when you are using Thread
s you must start them using the start()
method, not invoking the run()
method.