Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • 6
    Maybe. Depends on what OP meant by 'process'. "File locks are held on behalf of the entire Java virtual machine. They are not suitable for controlling access to a file by multiple threads within the same virtual machine." Commented Sep 25, 2008 at 6:59
  • @Stu: I know you have answered this question long time ago, but I hope you can elaborate what you mean when you said File locks are held on behalf of the entire Java virtual machine. They are not suitable for controlling access to a file by multiple threads within the same virtual machine Commented Jun 13, 2011 at 15:35
  • 4
    @Harry He's citing from the docs: download.oracle.com/javase/6/docs/api/java/nio/channels/… It means it's invisible to threads but affects other processes. Commented Jul 4, 2011 at 14:02
  • 1
    @Harry: To add even more to these necro-comments, imagine you are using Java for serving websites with Tomcat. You might have a lot of threads, each serving one request from a web-browser. However, they all control the same file locking mechanism like too many cooks in a kitchen. One request might finish in the middle of a second one, and suddenly your file got "unlocked" while you were still in the middle of something, and then some other process like a cronjob might lock it, and then you've unexpectedly lost your lock and your request cannot finish... Commented Jul 9, 2011 at 2:01