I'm using jdk1.1.8 and native threads under Linux. Is there a way to attach a standalone C executable started by a running java application to that current instance of the java application's JVM? My first instinct is to create a library that is not re-entrant and store the JVM pointer.

Alexander Krapf

I would be sceptical about this approach, though I have to admit that my development background is mostly on Windows.

It seems to me that you would be very likely run into trouble when you try to attach a thread from the C application to the JVM in a different process' address-space.

If you control both the Java application and the C application though, you could integrate them more tightly by launching the Java VM through a custom launcher that just happens to be your C application. That way, the JVM would be in the same process and you would not have to do all the other work-arounds.

Alternatively, I think that I would rely on some means of interprocess communication.

If your C application needs to do a lot of communication with the Java code, you might want to investigate JunC++ion, a tool that generates C++ proxy classes for Java classes. This way, your C code could easily call the Java classes through a C/C++ library. JunC++ion is currently only available on Wintel, but we're porting to Solaris and Linux (and others) and expect to have a beta ready soon. Check it out at http://www.codemesh.com.