What if a thread goes a long time without invoking a method that throws InterruptedException? Then it must periodically invoke Thread.interrupted, which returns true if an interrupt has been received. For example:
for (int i = 0; i < inputs.length; i++) {
heavyCrunch(inputs[i]);
if (Thread.interrupted()) {
// We've been interrupted: no more crunching.
return;
}
}
OCAJP 7, OCPJP 7
Nick Widelec wrote:
What does it mean "if a thread goes a long time without invoking a method that throws InterruptedException? Then It must periodically invoce Thread.interrupted"?
I mean if the thread gets interrupted, the situation will be handled in the try-catch clause as being a checked exception
Nick Widelec wrote:Could somebody enlighten me on the subject please? thanks in advance.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:Multi-threaded programming [...] actually quite rare.
OCAJP 7, OCPJP 7
Nick Widelec wrote:I am one of those who reckon the certification a good business card for freshers. And to whom says not http://www.reed.co.uk/jobs/junior-java-developer/23046503#/jobs?keywords=java%20certified
Jeff Verdegan wrote:I think you and I must have different definitions of "rare". Other than a handful of one-off batch data collection tools, I can't remember ever working on a real Java app that didn't involve a lot of multithreading.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Jeff Verdegan wrote:I think you and I must have different definitions of "rare". Other than a handful of one-off batch data collection tools, I can't remember ever working on a real Java app that didn't involve a lot of multithreading.
Hmmm. Really? Actually creating new Threads or Runnables and managing their execution?
You surprise me. What biz are you in, if you don't mind me asking?
You totally ruined the moon. You're gonna hafta pay for that you know. This tiny ad agrees:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|