Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

a question about somebody's lock code

 
michael opto
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Forget about it. I see now. I was thinking about something else. Sorry, please delete this post.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic