i create three threads in my main program. i have for loop in each thread. After executing the statements in the run() method , each thread automatically gets destroyed or killed by itself. correct? Is my understanding correct ?
IS there any Java standard reference where it mentions that there is no need to explicitly kill a thread and it does by itself. i have been trying to read and browse many articles. but still not getting 100% confidence.
I would highly appreciate if any expert over here could reply and help me out. Thanks in advance!!!
public class Demo {
TestA A = new TestA("TestA",threadAList);
TestA B = new TestB("TestB",threadBList);
TestA C = new TestC("TestC",threadCList);
}
class TestA implements Runnable {
Thread t;
public TestA(String name,List threadAList) {
System.out.println(name);
this.threadAList = threadAList;
t = new Thread(this);
t.start();
}
public void run() {
try {
System.out.println("TestA Thread started");
}
catch(Exception e) {
e.printStackTrace(log);
doing some action to move the faild file to a failure folder
}
finally {
log.close();
}
}
}
Yes, the thread is automatically destroyed and made available for garbage collection once its
Runnable‘srunmethod has returned.