Another thread can interrupt() it. From the JavaDoc on interrupt ...
public void interrupt() ... If this thread is blocked in an invocation of the wait(), wait(long), or wait(long, int) methods of the Object class, or of the join(), join(long), join(long, int), sleep(long), or sleep(long, int), methods of this class, then its interrupt status will be cleared and it will receive an InterruptedException.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Joined: Apr 02, 2006
Can I use interrupt in some other class to kill that instance which went into sleep?
You don't interrupt classes, you interrupt threads. Any object can call interrupt() on any thread (I think), but whether that thread takes any notice depends on what it's doing. If it's in sleep(), it will stop sleeping and throw InterruptedException.
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Joined: Apr 02, 2006
I want in Class B to kill main thread of Class A which went into infinite sleep. I am new to the topic.
Joined: Oct 30, 2001
Your questions aren't making any sense, I'm afraid. I think you'd better go read some introductory tutorials on Java threads. You'll find one or more on java.sun.com and probably loads by Googling.
Originally posted by Sonal Chawla: I want in Class B to kill main thread of Class A which went into infinite sleep. I am new to the topic.
Classes don't have have "threads". Classes have methods which are executed by threads. And in the cases where the method is not static, there may be more than on instance of that class, with that method, that is executed by threads.
This means, it is possible for a class, (and individual instances), to have no threads executing its methods, at a particular time. And it is also possible to have hundreds of threads executing its methods, as a particular time.
And if there is more than one thread executing the methods of a class, there is no concept of "main" thread. The nickname "main thread" is given to the thread that calls the main method of the class that starts the program.