JNI Invocation: static UN-initializers?

Discussion in 'Java' started by James Robert Leek, Aug 31, 2004.

  1. 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,
    --
    Jim Leek
     
    James Robert Leek, Aug 31, 2004
    #1
    1. Advertising

  2. In article <ch28ij$d77$>, James Robert Leek wrote:
    > 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
     
    A. Bolmarcich, Aug 31, 2004
    #2
    1. Advertising

  3. Wow, thanks a lot. That was great.
    --
    Jim Leek
     
    James Robert Leek, Aug 31, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brian Whitney
    Replies:
    0
    Views:
    586
    Brian Whitney
    Nov 5, 2003
  2. Dr. Dave Landis

    Problems with JNI Invocation Interface

    Dr. Dave Landis, Jan 12, 2004, in forum: Java
    Replies:
    1
    Views:
    721
    Dr. Dave Landis
    Jan 12, 2004
  3. Uri
    Replies:
    1
    Views:
    463
    Gordon Beaton
    Oct 21, 2004
  4. lucas

    JNI- Invocation API problem

    lucas, Nov 15, 2004, in forum: Java
    Replies:
    1
    Views:
    486
    Thomas Weidenfeller
    Nov 15, 2004
  5. CliffMacGillivray
    Replies:
    7
    Views:
    719
    Roedy Green
    Sep 15, 2005
Loading...

Share This Page