Search code examples
javaipcnioshared-memory

Does NIO deliver advantages even on consuming small serialized Stream from /dev/shm?


E.g. There is some app (outside of my src control) that produces thousands and thousands of serialized Map instances stored as /dev/shm/{some Map-ID}.ser . They are serialized using the plain old java.io.* package.

Can the code here, which is within my src control (to de-serialize Map instances), benefit from using NIO instead of plain old java.io.* package? Or, theoretically, given that these IO operations are on /dev/shm, is any NIO advantage presumed to be negligible?

private Map<Integer,String> deserializeMapFrKernelSHM(String shmKey) {
    Map<Integer,String> retM = null;
    try {
        FileInputStream frKernelSHM = new FileInputStream("/dev/shm/"+shmKey+".ser");
        ObjectInputStream in = new ObjectInputStream(frKernelSHM);
        retM = (Map<Integer,String>) in.readObject();
        System.out.println("Linux IPC shmop(GET) de-serialized Map<K,V> from /dev/shm/"+shmKey+".ser");
    }catch (Exception e) {
        e.printStackTrace();
    }
    return(retM);
}

Solution

  • Not really. It's almost impossible to combine Object Serialization with NIO.

    You could try a BufferedInputStream around the FileInputStream.