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
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.