, .
, while. :
while(expression)
boolean, :
while(Thread.currentThread.interrupted()){
if(!expression)
break;
}
That would be the perfect solution. Or you can use some booleans to also notify. Or perhaps if yours whileis queue based, add POISON_PILL, which will represent that it is time to exit the loop.
Daemon threadalso the solution mentioned above, but it depends on whether you want to store some data or close / manage some resources. Then it will be a problem.
Ultimately, to ensure reliability, you need to develop an appropriate shutdown policy.
Jatin source
share