• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

semaphores

 
Tom Nicki
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I read little bit about samaphores which appeared in java 5.
Following sempahore

created for each record would solve easly locing/unlocking problems.
No thread starvation problem because semaphores keeps threads in FIFO queue.
No need to think what is better: notify or notifyAll - there is no "wait" needed.

Does somebody of you use it?
Has anybody (using semaphores) got a good score in locking at the exam?
For me it looks too easy and I am getting suspicious.
In javadoc it is written that threads which cannot acquire semaphore will "lie dormant". Does this mean they consume "no CPU cycles"?

Greetings!
Tom
 
Petr Hejl
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Semaphore will appear in java 6 which is still beta.
 
Roy Mallard
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Petr - they are in 1.5, look at java.util.concurrent.Semaphore

Tom - yes you can use them if you want. You will still have to have some sort of timeout mechanism to prevent an inconsiderate client hogging a lock forever.
 
Petr Hejl
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Very sorry, I was blind.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic