I'm writing a program, so I'm having problems.
Why the finalize() method is not called?
public class ExOne extends Thread {
private String sD;
ExOne(String startUp, String shutDown){
System.out.println("Start-up message is: " + startUp);
sD = shutDown;
}
public void finalize() {
System.out.println("Shut-down message is: " + sD);
}
@Override
public void run() {
try {
for (int i = 0; i < 3; i++) {
System.out.println("Message " + String.valueOf(i));
Thread.sleep(1000);
}
}
catch (InterruptedException e){
System.out.println(e);
}
System.gc();
System.runFinalization();
}
}
public class Main {
public static void main(String[] args) {
ExOne exOneobj = new ExOne("start", "stop");
exOneobj.start();
}
}
So input is:
Start-up message is: start
Message 0
Message 1
Message 2
Process finished with exit code 0
And no message "Shut-down message is stop". Please help me.
What is wrong?