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 others get

    at the OS level (* nix)?
  • If the thread is put

    in MappedByteBuffer

    , is the content immediately visible to the other thread calling get

    ?

Thank.

To clarify the point: threads use a single instance MappedByteBuffer

, not multiple instances.

+3


source to share


1 answer


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 .

+1


source







All Articles