Skip to main content

Prevent JNI to be garbage collected

1 reply [Last post]
abelito_morelos
Offline
Joined: 2004-11-02
Points: 0

Hello!

I'm working in a project where there is some java code that needs to call native code(with JNI). In the past, the program was doing the call to the native function, the native function then made some work and the control was back to the Java application.

Now, there is the need for this native code to keep running after the Java code ends. The reason is that the Java code needs a lot of memory, and we can´t keep the Java code in memory just to allow the native code to keep running.

Some idea? Thanks!

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
bino_george
Offline
Joined: 2003-06-16
Points: 0

> Now, there is the need for this native code to keep
> running after the Java code ends.

When you say "Java code ends" I assume you mean that the
Java VM quits and you want the native application to
continue. So what you need to do is to write JNI code that
writes data to a shared memory segment or some storage
that is persistent accross processes. Then you spawn the
native application (a seperate process) which processes
that data and continues along, after the Java VM quits.

Regards,
Bino.