Java NIO has support for memory-mapped files. If multiple JVMs memory-map the same file they can use it as shared memory.
Here is an example of memory mapping a file.
try {
int shmSize = 1024;
RandomAccessFile file = new RandomAccessFile("shm.raw","rw");
// inialize file size
if(file.length() < shmSize) {
byte[] tmp = new byte[shmSize];
file.write(tmp);
file.seek(0); // seek back to start of file.
}
// memory-map file.
FileChannel ch = file.getChannel();
MappedByteBuffer shm = ch.map(FileChannel.MapMode.READ_WRITE, 0, shmSize);
ch.close(); // channel not needed anymore.
shm.load(); // force file into physical memory.
// now use the ByteBuffer's get/put/position methods to read/write the shared memory
} catch(Exception e) { e.printStackTrace(); }
On Linux you can create the shm.raw file in /dev/shm/ a memory based filesystem. This will help avoid any disk I/O.
For more details read this article Introduction to Memory-Mapped IO in Java
Also you will still need a way to syncronize read/writes to the shared memory. The sender JVM will need to signal the receiver JVM when a complete message has been written.
Using Java NIO's SocketChannel might be better for small messages since the receiver can be notified when a message is received. Shared memory will only really help when sending large messages.
For IPC between JVMs on different machines try
JIPC