Which options do I have for Java process communication?

Posted by Dmitriy Matveev on Stack Overflow See other posts from Stack Overflow or by Dmitriy Matveev
Published on 2010-03-10T14:18:42Z Indexed on 2010/04/19 6:03 UTC
Read the original article Hit count: 196

Filed under:
|

We have a place in a code of such form:

void processParam(Object param)
{
   wrapperForComplexNativeObject result = jniCallWhichMayCrash(param);
   processResult(result);
}

processParam - method which is called with many different arguments.

jniCallWhichMayCrash - a native method which is intended to do some complex processing of it's parameter and to create some complex object. It can crash in some cases.

wrapperForComplexNativeObject - wrapper type generated by SWIG

processResult - a method written in pure Java which processes it's parameter by creation of several kinds (by the kinds I'm not meaning classes, maybe some like hierarchies) of objects:
1 - Some non-unique objects which are referencing each other (from the same hierarchy), these objects can have duplicates created from the invocations of processParam() method with different parameter values. Since it's costly to keep all the duplicates it's necessary to cache them.
2 - Some unique objects which are referencing each other (from the same hierarchy) and some of the objects of 1st kind.

After processParam is executed for each of the arguments from some set the data created in processResult will be processed together. The problem is in fact that jniCallWhichMayCrash method may crash the entire JVM and this will be very bad. The reason of crash may be such that it can happen for one argument value and not for the other. We've decided that it's better to ignore crashes inside of JVM and just skip some chunks of data when such crashes occur. In order to do this we should run processParam function inside of separate process and pass the result somehow (HOW? HOW?! This is a question) to the main process and in case of any crashes we will only lose some part of data (It's ok) without lose of everything else. So for now the main problem is implementation of transport between different processes. Which options do I have? I can think about serialization and transmitting of binary data by the streams, but serialization may be not very fast due to object complexity. Maybe I have some other options of implementing this?

© Stack Overflow or respective owner

Related posts about java

Related posts about best-practices