jeudi 26 juin 2014

Should i nullify an interrupted thread?


Vote count:

0




I created a thread like this:



private Thread t = new Thread() {
@Override
public void run() {
try {
while(true) {
// do work
Thread.sleep(1000);
}
} catch (InterruptedException ex) {
}
}
};
t.start();


Then i interrupted it using t.interrupt().


As soon the thread stops and get on sleep() it will interrupt and become unusable, but will it stay on memory?


Do i have to call t = null, or the GC will take care of that?


I'm trying to dynamically interrupt the thread and recreate it when needed (using t = new Thread()), but im not sure if just interrupt() removes the old thread from memory. I've searched but couldn't find this specfic answer.



asked 47 secs ago






Aucun commentaire:

Enregistrer un commentaire