The following code leads to "java.lang.IllegalThreadStateException: Thread already started." the second time it is run through on the program.
updateUI.join();
if (!updateUI.isAlive())
updateUI.start();
updateUI.start()
updateUI.start()
updateUI.run()
From the Java API Specification for the Thread.start
method:
It is never legal to start a thread more than once. In particular, a thread may not be restarted once it has completed execution.
Furthermore:
Throws:
IllegalThreadStateException
- if the thread was already started.
So yes, a Thread
can only be started once.
If so than what do I do if I want to run the thread again?
If a Thread
needs to be run more than once, then one should make an new instance of the Thread
and call start
on it.