This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Threads and Synchronization and the fly likes Confusion in Lock Interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Confusion in Lock Interface" Watch "Confusion in Lock Interface" New topic
Author

Confusion in Lock Interface

vivek dhiman
Ranch Hand

Joined: Aug 05, 2011
Posts: 116

Hi
I have doubt to understand how lock works to maintain synchronization. I had the sample code which i was trying to implement synchronization using Lock. But it doesn't work.

Client Class

I want unique values till 300 in value.txt. Please tell me where i am wrong.
Thanks
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

vivek dhiman wrote:...But it doesn't work.
...
I want unique values till 300 in value.txt. Please tell me where i am wrong.

You need to learn to describe your problems better. ItDoesntWorkIsUseless (<- link). We know what you want, but what happens that you don't expect or what error messages do you get?


You create a new lock every time the method is called. So how do you expect it to synchronize?


Steve
vivek dhiman
Ranch Hand

Joined: Aug 05, 2011
Posts: 116

Thanks Steve. Now txt file have unique values till 300.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Confusion in Lock Interface