• Post Reply Bookmark Topic Watch Topic
  • New Topic

Major problem with record locking

 
Douglas Kent
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Submitted and got feedback that my record locking was poor. Here's what I wrote, basically a two-step process that involves sleeping and polling, which I gather is the problem:
LockStruct Lstr = (LockStruct)LockArray.get(record);
synchronized (Lstr.Lock) {
while ( Lstr.Locked ) {
try {
Thread.sleep( sleepTime );
}
catch (InterruptedException ex) {}
}
Lstr.ThreadThatHasLock = Thread.currentThread();
Lstr.Locked = true;
Any suggestions?
 
Sam Wong
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Off the top of my head, maybe you can try an event notification model to notify interested listeners that the record is freed. The listener may be a record locking manager that handles record locking requests. Just an idea. Hope it will spark your own ideas about this.
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!