Originally posted by Doit:
Can you please summarise this by giving one liners for..
Sorry, one-liners aren't really possible here.
What interrupt() does when a thread is
In running state?
I don't know if the thread will necessarily move to ready state as Ajith says. Threads can move back and forth from running to ready all the time anyway, so this doesn't make too much difference.
No exception is thrown. However the interrupted flag is set, which means that if you call interrupted() or isInterrupted(), they will return true. If the thread later goes from running state to waiting or sleeping state before interrupted flag is cleared via interrupted() method, then an InterruptedException will be thrown and the flag will be cleared.
In sleeping state?
The thread moves into ready state, and when it next gets a chance to execute an InterruptedException is thrown. No flag is set, so interrupted() returns false.
In yielding state?
There is no yielding state. Thread.yield() moves a thread from running state to ready state. If an interrupt() is called while a thread is in ready state, nothing happens until the thread moves back to running state. [Except, as Ajith says, this move may well occur sooner than it would have if interrupt() hadn't been called. I'm not sure about this part.] Once the thread has moved to running state, then see answer for running state, above.
In waiting state?
Same as for sleeping state above.
#2: Although wait() is an instance method inherited from Object, the thread it affects is always the current thread. When you have the statement
This forces the current thread to go into wait mode.
#3-5: I don't know what you mean here; sorry.