• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

threads giving up CPU resource

 
Bob Stone
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
typo - should be share object.wait().
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bob Stone
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 291
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't like the answers you got here? Sun site

It's bad manners to cross-post.
 
Bob Stone
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please forgive me once
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic