We have all read about finalizers and the reasons why you shouldn’t use it within your program.
However, I have a good way of making use of them.
If you have resources that need to be freed within your main program hint hint, then why not use finalizers in that one place?
It isn’t going to do anything bad. Java will have to handle all the horrible exceptions and internal mess afterwards and not in the program.
BTW: I realise this isn’t how you properly terminate threads.
class Main extends JFrame
{
.....................
public static void main(String[] elephants){
.....................
}
...........
protected void finalize() throws Throwable
{
super.finalize();
/*
most unsafe code in the universe!
then again, why should I care?
this is the JVM's mess now, my program has already ended by the time this is called.
this just makes it absolutely certain that everything is dead.
*/
tmpThread.interrupt(); //will throw an exception
tmpThread = null; //God no! Am I on drugs? Nulling a thread while it's quite possibly still RUNNING!!!
}
................
}