Can multiple threads see writes on a direct mapped ByteBuffer in Java?

前端 未结 7 2046
小鲜肉
小鲜肉 2020-12-08 07:31

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

7条回答
  •  隐瞒了意图╮
    2020-12-08 08:15

    I do not think that this is guaranteed. If the Java Memory Model doesn't say that it's guaranteed it is by definition not guaranteed. I would either guard buffer writes with synchronized or queue writes for one thread that handles all writes. The latter plays nicely with multicore caching (better to have 1 writer for each RAM location).

提交回复
热议问题