Originally posted by Harshit Rastogi:
see you can override finalize method but you have to keep 2 things in mind:
1) overridden method will not be called automatically by JVM, it needs to be explicitly called.
2) also dont forget to call object Class finalize() method from the overriden method. Why you want to know? just think and let me know if you dont understand
Hi Harshit
I made a
java application the override the finalize method. My intention is that this application will call another java application (login and transaction User Interface) and will be closed when user exited the login page.
The program direction is that upon starting the jar, the VM will call Main.class that will load Login.class and after login will load Transaction.class.
If your quotes above are correct, then my java should not close by itself nor calls the finalize method in the Main.class. But for some reason on some machine, the finalize method in Main.class was called although no method whatsoever calls it explicitly (unless got caught in an exception, which is not).
So, I renamed the finalize() method in Main.class and it works OK. Can you explain why this happens?
By the way the reason I used finalize in Main.class is so that if the software somehow exited unexpectedly, it will at least clean all the db connection, etc.
Thank you
Rendra