I want to stop a thread which does not have loop so like
while(!cancelled) //where cancelled is volatile variable
{
//
}
cannot be used as I want to execute long running task without loop, how to stop child threads if exception occurs in any of them from parent thread
@Oliver
As mentions in oracle docs
for (int i = 0; i < inputs.length; i++) {
heavyCrunch(inputs[i]);
if (Thread.interrupted()) {
// We've been interrupted: no more crunching.
return;
}
}
in above code if() will call only if heavyCrunch(inputs[i]) completed