Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

consumes no cpu cycles  RSS feed

James Clarke
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I implemented most of what is required for record locking, except the scenario where one client(thread) tries to lock a record already locked by another one. I can resolved the problem by putting the thread to sleep in a while loop that checks if the lock is available, but then I read this:
"Any attempt to lock a resource that is already locked should cause the current thread to give up the CPU, consuming no CPU cycles until the desired resource becomes available."

I dont see how this is possible there are two options I know of are to make a thread sleep/wait, neither of which has any mechanism that we can use to wake up a specific thread and if some or all threads are interrupted/notified but dont actually run then we have violated the above rule. I do not see how this is possible, Does anyone have any ideas of how this could be possible???

I did find a thread posting on 02/27/2007 by Andrew Monkhouse which he seems to hint that this is possible:

quote riginally posted by Maciej Miklas
I would not do that, specially that my specification says: �consuming no CPU cycles until the desired resource becomes available� and this is not the case.

Adrew: Good point.

As James notes, this is not a "must" condition, however it is worth considering.

Can you elaborate on this Andrew? if your still around!!


It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!