Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A question of lock

 
Paul Sun
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi:
I meet a problem of lock. For example, A,B and C
want to book the same ticket at the same time. Then A will book it and B,C are locked. But when the lock is released by A, lockManager will notify all members, B and C. So that, B and C will try to book it at same time. I think, I need to create a FIFO array to store waitting members and let them book ticket in order. Please give me some advice. Thanks.
Paul
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul,
That is what wait, and notifyAll in the Object class is for. When you get an object lock,there is a battle for the lock when three client go for it.
When A releases the lock it calls notifyAll() and lets B and C fight for the lock. That is the best way to handle it, because it is all handled by the JVM. That is threads at it's greatest.
So it is better to use what is already provided for you than trying to reinvent the wheel. I remember when I was a kid programmer I kept trying to reinvent the wheel. You should see how many triangular wheels I have, the most bizarre one is Red and has Big letters on it saying STOP.
Mark
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Mark Spritzler:
... I remember when I was a kid programmer I kept trying to reinvent the wheel. You should see how many triangular wheels I have, the most bizarre one is Red and has Big letters on it saying STOP.

I wish I could remember when I was a kid programmer! I vaguely recall terms like punch-cards, EBCDIC, and magnetic core. I even remember praying for 16K of core (RAM) instead of the 8K we had to work with.
Michael Morris
OFP
(Old Fart Programmer)
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I programmed on a Vic 20 when it had only 4K of memory. and before that was the Commodore Pet and the Trash 80's by Radio Shack.
Mark
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mark

Well I programmed on a Vic 20 when it had only 4K of memory. and before that was the Commodore Pet and the Trash 80's by Radio Shack.

Those guys are state of the art compared to my firsts: the IBM 1130 whose console was a teletype and whose printer was nearly as big as Volkswagen and slower than a one-legged dog; and the IBM 360 "mainframe".
You did remind me of the last assembly routine I wrote. It was on the old Trash 80, an interrupt routine for a (now defucnt) Houston Instruments plotter.
Michael Morris
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic