Allocating memory outside JVM and using it inside JVM

后端 未结 2 557
清歌不尽
清歌不尽 2021-02-13 18:28

Is it possible to create a persistent memory object outside JVM memory that can be used inside the JVM as an object, so that it survives a JVM restart?

Particular idea i

2条回答
  •  无人及你
    2021-02-13 19:24

    Yes, this is completely possible, even without JNI.

    The idea is to have a MappedByteBuffer backed by a "file" on tmpfs filesystem. E.g. on Linux you can use /dev/shm (or /run/shm) mountpoint for that.

    The performance of such MappedByteBuffer will be the same as for other Direct ByteBuffers, but it will persist the JVM restart, i.e. you can map this "file" again in a new JVM. (I write "file" in quotes, because it looks like a regular file for application, but it is actually a shared memory region that resides in RAM). We actively use this technique for our production in-memory caches.

提交回复
热议问题