If I have a Thread
running in a class called Menu
, what happens to the thread if I were to reinitialize Menu
?
public class Menu {
private Thread thread = new Thread(new Runnable() {
@Override
public void run() {
while(!thread.isInterrupted()){
// Thread code
}
}
});
public Menu() {
thread.start();
}
public static void main(String[] args) {
Menu menu = new Menu(); //Original
menu = new Menu(); // New
}
}
Does the thread in the original initialization continue running along with the new one or does it stop?
*Edited in attempt to make it clearer although I got my answer.