0
public class ThTest1 {

    public static void main(String args[]) {

        System.out.println("Main started ");


        System.out.println("length: "+args.length);


        for (int i=0;i<args.length;i++){

           System.out.println("ARGS: "+i+"\t"+args[i]);
         }

         Thread th=Thread.currentThread();
         ThreadGroup tg= th.getThreadGroup();

         new Student();

         for(int i=0;i<10;i++)  {

              System.out.println(i+"\t"+th.getName()+"\t"+tg.getName());

         }

         System.out.println("Main completed");

    }

}

class Student {

    public void Finalize() {

        Thread th=Thread.currentThread();

        ThreadGroup tg= th.getThreadGroup();

        for(int i=20;i<40;i++) {

            System.out.println(i+"\t"+th.getName()+"\t"+tg.getName());
        }

   }

}
PM 77-1
  • 12,933
  • 21
  • 68
  • 111
scavy
  • 1
  • 1
  • You really need to format your code properly when you post a question. It can make it extremely difficult for people to figure out what's going on in your code, otherwise. – Paul Richter Nov 04 '13 at 18:01
  • 1
    I did RAS (Reformatting As Service) for OP. – PM 77-1 Nov 04 '13 at 18:03

1 Answers1

4

finalize() should match in name with Object#finalize() in order to override it and be actually used during finalization. Name it with a lowercase f:

public void finalize() {

    Thread th=Thread.currentThread();

    ThreadGroup tg= th.getThreadGroup();

    for(int i=20;i<40;i++) {

        System.out.println(i+"\t"+th.getName()+"\t"+tg.getName());

    }
}
nanofarad
  • 40,330
  • 4
  • 86
  • 117