I am having a real hard time finding a way to start, stop, and restart a thread in Java.
Specifically, I have a class Task
(currently implements Runnable
) in a file Task.java
. My main application needs to be able to START this task on a thread, STOP (kill) the thread when it needs to, and sometimes KILL & RESTART the thread...
My first attempt was with ExecutorService
but I can't seem to find a way for it restart a task. When I use .shutdownnow()
any future call to .execute()
fails because the ExecutorService
is "shutdown"...
So, how could I accomplish this?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…