1 : 6 in the state of the thread State of the thread is clearly defined in JavaThread class, a total of six kinds: CPU scheduling reasons, Runnable state, there are two cases: 1: running, 2 : CPU can run at any time. If a thread is already running over, you call the start () method throws an exception.
2: How to terminate a running thread
Incorrect method: 1 : the JDK is not recommended stop () method to terminate the thread, (stop: terminate the thread and clear information monitor lock) JDK is not recommended, as it will lead to thread-safety issues. Forcibly interrupted thread, causes the thread to launch the task is not safe and may lead to data inconsistency.
2.1: Recommended method: interrupt
Interrupt method after calling thread. Thread safe termination, and throws an exception. (Actually just a set interrupt flag to the thread, the thread will continue to run until the end of security.)
2.1: achieved through termination flag