aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Threads" Watch "Threads" New topic
Author

Threads

Girish Nagaraj
Ranch Hand

Joined: Apr 19, 2006
Posts: 153
class A extends Thread {

public void run() {

try {

Thread.sleep(2000);
} catch (InterruptedException ie) {

System.out.println("Thread Interrupted");
}

System.out.println("\n" + interrupted());
System.out.println(interrupted());
}
}

class X {

public static void main(String[] args) {

A t = new A();
t.start();
t.interrupt();
}
}

Output
------
Thread Interrupted
false
false // Why false here

interrupted() resets interrupt flag right?


Thanks in Advance.
wise owen
Ranch Hand

Joined: Feb 02, 2006
Posts: 2023
Each Thread has an associated boolean interruption status. Invoking t.interrupt for some Thread t sets t's interruption status to true, unless Thread t is engaged in Object.wait, Thread.sleep, or Thread.join; in this case interrupt causes these actions (in t) to throw InterruptedException, but t's interruption status is set to false.
Girish Nagaraj
Ranch Hand

Joined: Apr 19, 2006
Posts: 153
Thanks wise
Amirr Rafique
Ranch Hand

Joined: Nov 14, 2005
Posts: 324
hi wise
can you plz explain bit more

Thanks


"Know where to find the solution and how to use it - that's the secret of success."
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Threads