What will happen if I assign a new thread object to a thread variable and run it while the thread object that was bound to the variable before is still running? Will it be garbage collected and destroyed? Or will they run in parallel?
Something like this:
class ThreadExample implements Runnable {
public void run() {
// Something that runs for a long time
}
}
public class ThreadExampleMain {
public static void main(String[] args) {
// Client Code
ThreadExample e = new ThreadExample();
Thread t = new Thread(e);
t.start();
e = new ThreadExample();
t = new Thread(e);
t.start();
}
}
Will this start two threads running parallelly or will the first thread stop and be garbage collected?