OverlappingFileLockException when trying to lock a filechannel twice in shared mode

Siddharth Jain siddhsql at gmail.com
Fri Sep 15 01:26:33 UTC 2023


its confusing at best.

https://docs.oracle.com/javase/8/docs/api/java/nio/channels/FileLock.html

>A shared lock prevents other concurrently-running programs from acquiring
an overlapping exclusive lock, but does allow them to acquire overlapping
shared locks.

>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

so it doesn't specify the behavior within same program and across threads
and what i am finding (for benefit of anyone who comes across this) is that
there is an exception if the same thread tries to lock the channel twice in
shared mode (original email) but there is no exception if two different
threads within same program try to do it.

On Thu, Sep 14, 2023 at 3:28 PM Brian Burkhalter <
brian.burkhalter at oracle.com> wrote:

> A "concurrently running program” means a separate process. You are
> attempting to acquire two overlapping locks in the *same* process.
>
> Brian
>
> On Sep 14, 2023, at 2:21 PM, Siddharth Jain <siddhsql at gmail.com> wrote:
>
>
> https://docs.oracle.com/javase%2F7%2Fdocs%2Fapi%2F%2F/java/nio/channels/FileLock.html
> A file lock is either *exclusive* or *shared*. A shared lock prevents
> other *concurrently-running programs* from acquiring an overlapping
> exclusive lock, *but does allow them to acquire overlapping shared locks.*
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/nio-dev/attachments/20230914/1b1d012d/attachment.htm>


More information about the nio-dev mailing list