Closed zcmiyano closed 3 years ago
interrupt()
will cause the thread to throw an InterruptedException
. If you didn't catch such exception, the thread will exit and it will not work anymore. If you catch it, the thread will just continue running.
The reason why you are suggested to call Thread.interrupt()
is that the thread may be waiting on the paramQueue
, when you call pause()
. So It will not go in to paused
state since it is blocked. interrupt()
is used to interrupt the thread and make it stop blocking and pause itself.
You can choose to not use interrupt()
if you can implement the functionality in your own way.
Thanks for your reply, may I ask why the thread may be waiting on the paramQueue (what's it?) when I call pause() (in the piece?)?
paramQueue is one way to let main thread (which calls getCandidateMove) notify piece thread that it's time to propose a move. The parameters are delievered to piece thread through the queue.
You can also choose not to use this queue (and also interrupt()) as long as you implement the functionality correctly.
In the hint of Pause Piece Action, it is said that
Do we need to use thread#interrupt() here? It is also used in the Piece terminate action. Can an interrupted thread be resumed?