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?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.