File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Thread Ques Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Thread Ques" Watch "Thread Ques" New topic

Thread Ques

Swati Gupta
Ranch Hand

Joined: May 28, 2002
Posts: 106
From Jqplus

What will be the effect of interrupt() method here.
The answer says it will run forever.
I thought due to interrupt() the flag will set to true.
I am really doing very bad in thread ques in mock exams.
[ June 11, 2002: Message edited by: swati gupta ]
Abhijeet Gholkar

Joined: Jun 11, 2002
Posts: 25
class A extends Thread
public void run()
System.out.println("Starting loop");
public class TestClass
public static void main(String args[]) throws Exception
A a = new A();
Try this code to putoff the thread
Bonnie Beach-Morin

Joined: Jun 13, 2002
Posts: 13
If your looking for a reason as to why it will run forever, it's because the interrupted() method doesn't actually do anything other than set a flag variable. The run method of class A never bothers to check the interrupted flag, so it doesn't know it should stop and runs forever.
Another solution would be to do the following

I agree. Here's the link:
subject: Thread Ques
It's not a secret anymore!