When a Thread is finished, you cannot run it once more, using start() method: it throws an Exception. Could anyone explain, why? What stands behind such an architectural decision?
Because the way to have code executed in a separate thread is not to create a thread, which is linked to system view of what is a thread (there are endless details on distinction between green and system threads), but to create a Runnable, and have it executed by a Thread.
For optimal code (since creation of threads is time-consuming), I would even recommand you not to directly have your Runnable executed by a thread, but rather by an ExecutorService, which will allow you to use a thread pool without bothering about all those details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With