I have the following thread:
public void start() { isRunning = true; if (mainThread == null) { mainThread = new Thread(this); mainThread.setPriority(Thread.MAX_PRIORITY); } if (!mainThread.isAlive()) { try { mainThread.start(); } catch (Exception e) { e.printStackTrace(); } } }
At some point I want to stop him:
public void stop() { isRunning = false; System.gc(); }
When start() is called, the following exception is thrown again:
java.lang.IllegalThreadStateException
Specifying a line of code mainThread.start() .
What is the best way to start / stop a thread? how can i make this thread multiple?
Thanks!
source share