File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes a question about somebody's lock code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "a question about somebody Watch "a question about somebody New topic
Author

a question about somebody's lock code

michael opto
Greenhorn

Joined: Jan 17, 2002
Posts: 29
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

Joined: Jan 17, 2002
Posts: 29
Forget about it. I see now. I was thinking about something else. Sorry, please delete this post.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: a question about somebody's lock code