I got the following error when I try to start again my thread.
Exception in thread "Thread-1" java.lang.IllegalThreadStateException
at java.lang.Thread.start(Unknown Source)
at com.jrat.server.Server.run(Server.java:159)
Here is the line:
if (!t.isAlive()) t.start();
The code can be executed many times as it is in a loop (socket handler).
As far as I know, this error means that it can’t start a new Thread because it is already running. What’s weird is I have a isAlive before.
Any idea why it is like that?
Thanks.
No, it means you can’t start a thread which has already been started.
You can’t restart a thread, which is what you’re trying to do. From the documentation for
start():You should probably be using an
ExecutorServiceinstead, at a guess – but it’s not really clear what you’re trying to do.