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?