I\'m working on something that uses ByteBuffers built from memory-mapped files (via FileChannel.map()) as well as in-memory direct ByteBuffers. I am trying to understand th
One possible answer I've run across is using file locks to gain exclusive access to the portion of the disk mapped by the buffer. This is explained with an example here for instance.
I'm guessing that this would really guard the disk section to prevent concurrent writes on the same section of file. The same thing could be achieved (in a single JVM but invisible to other processes) with Java-based monitors for sections of the disk file. I'm guessing that would be faster with the downside of being invisible to external processes.
Of course, I'd like to avoid either file locking or page synchronization if consistency is guaranteed by the jvm/os.