runFinalizersOnExit is deprecated, but this should be no problem for most users....
However, I want to use HSQL with the JVM wonka, and in wonka this method is not implemented at all. Since just commmenting out is a bad idea, I substituted that thing with a shutdownhook. See patch
Any ideas or suggestions?
Cheers Jochen
--- hsqldb-orig/src/org/hsqldb/LockFile.java Sat Feb 7 16:10:47 2004
+++ hsqldb/src/org/hsqldb/LockFile.java Tue Feb 24 17:35:36 2004
@@ -192,6 +192,7 @@
* And opaque reference to this object's heatbeat task.
*/
private Object timerTask;
+
/**
* Attempts to read the hearbeat timestamp from this object's lock file
@@ -814,7 +815,13 @@
if (locked) {
writeMagic();
startHeartbeat();
-
+ //substitute for runFinalizersOnExit
+ //the Thread will keep a reference to
this LockFile Object,
+ // so it won't be gc'ed :-(((
+ //however, there won't be too many
lockfiles around...
+
Runtime.getRuntime().addShutdownHook(new FinalHook(this));
+/* wonka does not have the deprecated runFinalizersOnExit(true)
+a shutdownhook should do the job instead.
try {
// attempt to ensure that tryRelease() gets called if/when
@@ -825,6 +832,7 @@
} catch (Exception e) {
trace(mn + e.toString());
}
+ */
} else {
try {
releaseImpl();
@@ -938,7 +946,25 @@
* if any, that it has on its lock file.
*/
protected void finalize() throws Throwable {
- trace("finalize(): calling tryRelease()");
+ trace("finalize(): calling tryRelease()");
tryRelease();
+
}
+
+ private class FinalHook extends Thread{
+ private LockFile lockFile;
+ private FinalHook(){};
+ public FinalHook(LockFile _lockFile){
+ lockFile=_lockFile;
+ }
+
+ public void run(){
+ lockFile.trace("finalize(): calling tryRelease()");
+ try{
+ lockFile.tryRelease(); }
+ catch(Throwable t){}//what to do now?
+ }
+
+
+ }
}
