Does it support card-enabled files at the same time?
My application requires concurrent access to a data file using memory mappings. My goal is to make it scalable on a shared memory system. After examining the source code of the memory libraries implementation with memory, I cannot figure out:
- Is it legal to read from
MappedByteBuffer
multiple threads?get
blocks othersget
at the OS level (* nix)? - If the thread is
put
inMappedByteBuffer
, is the content immediately visible to the other thread callingget
?
Thank.
To clarify the point: threads use a single instance MappedByteBuffer
, not multiple instances.
Buffers are not thread safe and their access must be controlled by appropriate timing; see the Thread Safety section at http://docs.oracle.com/javase/6/docs/api/java/nio/Buffer.html . ByteBuffer is a subclass of Buffer and therefore has the same thread safety issue.
Trying to do scalable memory mapped file usage on a shared memory system looks very suspicious to me. Using memory mapped files for performance. When you are moving to shared systems, the search for performance should be one of the factors where you should have a low priority. Not that you are looking for a slow system, but you will have so many other problems that just make it work, should be your first (and only?) Priority in the beginning. I wouldn't be surprised if at the end you need to replace your concurrent data file access using memory mappings with something else.
For some ideas like using Exchanger see Can multiple threads see entries on a directly mapped ByteBuffer in Java? and Options to enable the Java ByteBuffer stream safely .
source to share