Any concept of shared memory in Java

后端 未结 10 504
猫巷女王i
猫巷女王i 2020-11-29 05:33

AFAIK, memory in Java is based on heap from which the memory is allotted to objects dynamically and there is no concept of shared memory.

If there is no concept of s

相关标签:
10条回答
  • 2020-11-29 06:04

    Peter Lawrey's Java Chronicle project is worth looking at.

    These are some tests that I had done a while ago comparing various off-heap and on-heap options.

    0 讨论(0)
  • 2020-11-29 06:06

    MappedBus (http://github.com/caplogic/mappedbus) is a library I've added on github which enable IPC between multiple (more than two) Java processes/JVMs by message passing.

    The transport can be either a memory mapped file or shared memory. To use it with shared memory simply follow the examples on the github page but point the readers/writers to a file under "/dev/shm/".

    It's open source and the implementation is fully explained on the github page.

    0 讨论(0)
  • 2020-11-29 06:07

    Since there is no official API to create a shared memory segment, you need to resort to a helper library/DDL and JNI to use shared memory to have two Java processes talk to each other.

    In practice, this is rarely an issue since Java supports threads, so you can have two "programs" run in the same Java VM. Those will share the same heap, so communication will be instantaneous. Plus you can't get errors because of problems with the shared memory segment.

    0 讨论(0)
  • 2020-11-29 06:07

    There are at least 2 ways to do it - RAM Drive or Apache APR.

    Details here and here with some performance measurements.

    0 讨论(0)
提交回复
热议问题