JNI Invocation: static UN-initializers?

J

James Robert Leek

I'm writing language interoperability tools for scientific computing. It
supports C, C++, Fortran, Python, and Java through the JNI. Anyway, my
boss would like to add static uninitializers. A static unitializer is the
opposite of a static initializer. Insted of being a static function that
is run when a class is statically loaded, a static uninitializer is run
once when the class is staticly unloaded. In general this means when the
JVM is unloaded, it should run some code for each class that has been
loaded.

So here's the question:

Is this even freakin' possible in Java? There are 2 ways I can think of
where it might work:

If the feature already exists in Java (As it does with C, and fortran)
such that when I call DestroyJavaVM, Java calls code. However, I
understand that DestroyJavaVM doesn't even work, so that might be a no go.

Another possibility would be if there is some way to have Java find all
the classes currently loaded and call some function on them, is that
possible?

Thanks,
 
A

A. Bolmarcich

I'm writing language interoperability tools for scientific computing. It
supports C, C++, Fortran, Python, and Java through the JNI. Anyway, my
boss would like to add static uninitializers. A static unitializer is the
opposite of a static initializer. Insted of being a static function that
is run when a class is statically loaded, a static uninitializer is run
once when the class is staticly unloaded. In general this means when the
JVM is unloaded, it should run some code for each class that has been
loaded.

So here's the question:

Is this even freakin' possible in Java? There are 2 ways I can think of
where it might work:

If the feature already exists in Java (As it does with C, and fortran)
such that when I call DestroyJavaVM, Java calls code. However, I
understand that DestroyJavaVM doesn't even work, so that might be a no go.

Ignoring DestroyJavaVM concerns, see the API documentation for the
addShtudownHook method at

http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html#addShutdownHook(java.lang.Thread)
Another possibility would be if there is some way to have Java find all
the classes currently loaded and call some function on them, is that
possible?

A classFinalize method was part Java 1, but it was never used. You will
need to worry about this only if the classes that need to be finalized
are subject to garbage collection, which occurs only if the classes are
loaded by a custom class loader that becomes unreachable. In that case,
see

http://java.sun.com/docs/books/jls/class-finalization-rationale.html

and

http://java.sun.com/docs/books/jls/unloading-rationale.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top