Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Originally posted by Doit:
Thanks Ajit.
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.
- Thanks.
"I'm not back." - Bill Harding, Twister
"I'm not back." - Bill Harding, Twister
"I'm not back." - Bill Harding, Twister
Uncontrolled vocabularies
"I try my best to make *all* my posts nice, even when I feel upset" -- Philippe Maquet
#2: Although wait() is an instance method inherited from Object, the thread it affects is always the current thread. When you have the statement
<code><pre> someObject.wait();</pre></code>
This forces the current thread to go into wait mode.
#3-5: I don't know what you mean here; sorry.
If a regular clown is funny, then a larger clown would be funnier. Math. Verified by this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|