Java – thread status exception
•
Java
When I try to restart my thread, I receive the following error
Exception in thread "Thread-1" java.lang.IllegalThreadStateException at java.lang.Thread.start(UnkNown Source) at com.jrat.server.Server.run(Server.java:159)
This is a line:
if (!t.isAlive()) t.start();
The code can be executed multiple times in a loop (socket handler) As far as I know, this error means that it cannot start a new thread because it is already running Strangely enough, I had an isalive
Do you know why?
thank you.
Solution
No, this means that you cannot start a thread that has already been started
You cannot restart the thread. This is what you are trying to do Start with the document for start():
You should probably use executorservice instead of guessing - but you really don't know what you're going to do
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码