B
Boris
Is there any guarantee that finalize() is called only after a constructor
finishes? I wonder as the documentation at
http://java.sun.com/javase/6/docs/api/java/lang/Object.html#finalize()
says that the "Java programming language does not guarantee which thread
will invoke the finalize method".
I ask as I have a Java class which makes two JNI calls in the constructor.
In finalize() another JNI call is made to release resources. If the class
is instantiated thousands of times in a loop without storing references I
get an exception or crash at some point as the second call in the
constructor tries to use a resource which strangely has been released
already. If I change the program and store references to make sure that
the garbage collector releases all objects only after the loop everything
works fine. I'm now trying to understand if there is a race condition as
the second JNI call in the constructor doesn't see the resource sometimes.
Any ideas?
Thanks in advance,
Boris
finishes? I wonder as the documentation at
http://java.sun.com/javase/6/docs/api/java/lang/Object.html#finalize()
says that the "Java programming language does not guarantee which thread
will invoke the finalize method".
I ask as I have a Java class which makes two JNI calls in the constructor.
In finalize() another JNI call is made to release resources. If the class
is instantiated thousands of times in a loop without storing references I
get an exception or crash at some point as the second call in the
constructor tries to use a resource which strangely has been released
already. If I change the program and store references to make sure that
the garbage collector releases all objects only after the loop everything
works fine. I'm now trying to understand if there is a race condition as
the second JNI call in the constructor doesn't see the resource sometimes.
Any ideas?
Thanks in advance,
Boris