Reputation: 1
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());
}
}
}
Upvotes: 0
Views: 68
Reputation: 41311
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());
}
}
Upvotes: 4