Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Java NIO has support for memory-mapped files. If multiple JVMs memory-map the same file they can use it as shared memory.</p> <p>Here is an example of memory mapping a file.</p> <pre><code>try { int shmSize = 1024; RandomAccessFile file = new RandomAccessFile("shm.raw","rw"); // inialize file size if(file.length() &lt; 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(); } </code></pre> <p>On Linux you can create the shm.raw file in /dev/shm/ a memory based filesystem. This will help avoid any disk I/O.</p> <p>For more details read this article <a href="http://www.developer.com/java/other/article.php/10936_1548681_1" rel="noreferrer">Introduction to Memory-Mapped IO in Java</a></p> <p>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.</p> <p>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.</p> <p>For IPC between JVMs on different machines try <a href="http://www.garret.ru/jipc/jipc.html" rel="noreferrer">JIPC</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload