Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

FileLock on file accessed from multiple virtual machines  RSS feed

 
Ravi Danum
Ranch Hand
Posts: 154
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

I have a web service that allows a file to be uploaded. The web service can be deployed on multiple machines, but the file is to be stored within the same file system. Can I use java.nio.channels.FileLock and Filechannels to lock a file when it gets created so that no other upload will try and save the same file?

Thanks.

Ravi
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you try it out with a little test program:
You start this code once, and don't press enter yet. You then start it again in another JVM. See what happens.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!