File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Threads and Synchronization and the fly likes threads giving up CPU resource Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "threads giving up CPU resource" Watch "threads giving up CPU resource" New topic
Author

threads giving up CPU resource

Bob Stone
Greenhorn

Joined: Mar 28, 2007
Posts: 12
Hi all,

I am writing an API that is required to be thread-safe. As I know if a share object is enclosed by a sychronized block, any attempt to lock the object that is already locked will be blocked. My questions are i.) is it using thread.wait() to cause those threads giving up the CPU resource? ii.) If using reentrantreadWriteLock().writeLock() instead of synchronized block, how to let those blocked threads giving up CPU time?


Thanks in advance

bob
Bob Stone
Greenhorn

Joined: Mar 28, 2007
Posts: 12
typo - should be share object.wait().
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
The question is not very clear, but maybe the following will help.

If a thread is blocked waiting to gain the lock on an object's monitor (i.e. it is trying to enter a synchronized block), that thread uses hardly any CPU. Similarly, if a thread is in wait(), waiting for a notify() from another thread, the waiting thread uses hardly any CPU.


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Bob Stone
Greenhorn

Joined: Mar 28, 2007
Posts: 12
Thanks Peter,

I've checked with some books in which specify that a thread gives up the CPU resource and the lock on a shared object if it encountered a wait() call in the object. So the question left is how can I use reentrantReadWriteLock().writeLock() to do the same thing as done by sychronized block and wait() call? Once again, many thanks for your reply.


Bob
Edward Harned
Ranch Hand

Joined: Sep 19, 2005
Posts: 291

You don't like the answers you got here? Sun site

It's bad manners to cross-post.


Ed's latest article: A Java Parallel Calamity http://coopsoft.com/ar/Calamity2Article.html
Bob Stone
Greenhorn

Joined: Mar 28, 2007
Posts: 12
please forgive me once
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: threads giving up CPU resource