Search code examples
javajava-native-interfaceipcshared-memoryjna

better Java IPC@Linux tactic: (a) java.nio File API on /dev/shm or (b) JNI to shmctl(2)?


We want write a Java 7 program that will boot (via 2 cmd line invokes) as two separate JVM process instances. We want these 2 processes to communicate with each other using native Linux kernel shared-memory IPC resources.

Does anyone have any insight as to which of these 2 approaches may have more merit?

  1. Use java.nio.* API on /dev/shm
  2. Use JNI bridge to C++ code that makes native shmctl() system calls

?


Solution

  • I vote "NIO and /dev/shm".

    But before making any final decisions, you should also consider other options, including CLIP:

    Sockets, message queues and named pipes are other IPC methods I wouldn't necessarily dismiss out-of-hand. IMHO...