The operating environment of this tutorial: Windows 7 system, Java 10 version, DELL G3 computer.
1. New : Threads that have not been started after creation are in this state.
2. Runnable : includes Running and Ready in the operating system thread state. That is, the thread in this state may be executing, or it may be waiting for the operating system to allocate execution time to it.
3. Waiting : Threads in this state will not be allocated processor execution time. They have to wait to be explicitly awakened by other threads. The following method will cause the thread to fall into a waiting state:
The Object::wait() method does not set the Timeout parameter;
Thread::join() method without setting Timeout parameter;
LockSupport::park() method.
4. Timed Waiting : Threads in this state will not be allocated processor execution time, but they do not need to wait to be explicitly awakened by other threads. They will be automatically awakened by the system after a certain period of time. The following method will put the thread into a deadline waiting state:
Object::wait() method with Timeout parameter set;
Thread::join() method with Timeout parameter set;
LockSupport::parkNanos() method;
LockSupport::parkUntil() method.
5. Blocked : The thread is blocked. The difference between "blocked state" and "waiting state" is that "blocked state" is waiting to acquire an exclusive lock. This event will occur when another thread gives up the lock. occurs; and "waiting state" is waiting for a period of time, or for the wake-up action to occur. The thread will enter this state while the program is waiting to enter the synchronization area.
6. Terminated : The thread status of the terminated thread, the thread has ended execution.
The above are the six states of Java threads. I hope they can be helpful to everyone.
More Java learning guide: java tutorial