This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes 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