java - Manage a lock in a file system -


i have 2 java processes , need make sure not simultaneously access directory /dir. not sure how implement behaviour.

my idea define file lock.txt , like

if not (lock.txt exists)    {      create lock.txt content "process 1"     in /dir     delete lock.txt    } 

but guess run kind of race condition if both processes check simultaneously.

edit: java processes separate programs.

look @ filelock class here: http://docs.oracle.com/javase/6/docs/api/java/nio/channels/filelock.html

you have found bit of googling


Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -