This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Thread Monitor Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Thread Monitor" Watch "Thread Monitor" New topic
Author

Thread Monitor

James X Williams
Greenhorn

Joined: Dec 07, 2006
Posts: 11
Friends:
Does the thread lose the monitor on sleep, yield or block. I feel it does not.
Can some one confirm this.
James
Mani
Ranch Hand

Joined: Apr 20, 2000
Posts: 50
sleep() and yield() doesnot release the lock on the object.
I'm not sure abt block.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18670
Not on block either. The only ways I remember that a lock on a monitor is given up are: (1) when the synchronized method or block ends, and (2) when the monitor's wait() method is called (it's then re-acquired after notify() in order for the thread to resume in synchronized code).


"I'm not back." - Bill Harding, Twister
bongadi
Greenhorn

Joined: Apr 17, 2000
Posts: 23
A thread gets blocked
- by calling sleep(x);
- by calling suspend() (deprecated);
- by calling wait();
- due to I/O block
- while waiting for an object lock or "monitor"
The thread which has acquired the lock and is in critical section
would not give up the lock when it calls sleep(), suspend() or
when its blocking for i/o.
The thread would give up the lock when the object it is locking
on calls wait(),
SO I think you are correct.
sleep() and yield() are Thread methods and blocking is
a consequence of an operation. So they cannot influence
the lock acquired by an Object.
Originally posted by James:
Friends:
Does the thread lose the monitor on sleep, yield or block. I feel it does not.
Can some one confirm this.
James

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Thread Monitor
 
Similar Threads
IllegalMonitorStateException
Monitor
monitor question
Will Thread release the lock it holds when it enters sleep state?
Monitor