• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

a question about somebody's lock code

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I saw somebody's lock code here like this:
private Set set = Collections.synchronizedSet(new HashSet());
if(record == -1){
for(int i = 1; i<=recordCount; i++)
lock(i);
}else{
synchronized(set){
while( (set.contains(new Integer(record))) ){try{
set.wait();
}catch(InterruptedException e){}
}
set.add(new Integer(record));
//
}
}
I think the set.notifyAll() should be added to the comment to wake up other threads which are waiting on the set object, while the current thread can do something else. Am I missing anything here? Please.
 
michael opto
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Forget about it. I see now. I was thinking about something else. Sorry, please delete this post.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic