Processes and threads are independent, while threads are not necessarily independent. Threads in the same process may interact with each other. Thread execution cost is small, but not conducive to the management and protection of resources; The process is the opposite.
In order to improve the combined utilization of CPU and IO devices, one thread performs CPU calculations while the other thread performs IO operations. In the multi-core era, multiple cores are used to improve CPU utilization.
New state new-(Thread.start())-> Runnable
Running -(yield(), system scheduling)-> Ready Ready -(system scheduling gets time slice)-> RUNNING
— Waiting for access to a synchronized method or block –> (lock acquired)–> running
Running –(Object.wait (), Thread.join (), locksupport.park ())–>waiting waiting () running –(Object.wait (), Thread.join (), locksupport.park ())–>waiting waiting –(object.notify(),object.notifyAll(),lockSupport.unpark(thread))–>running
Time_waiting timeout means that the current thread will automatically return to the running state running over a period of time –(object.wait(long),thread.join(long),lockSupport.parkNanos(),lockSupport.parkUntil(),thread.sleep(long))–>time_waitin g time_waiting–(object.notify(),object.notifyAll(),lockSupport.unpark(thread))–>running
Terminated state
Running — –>terminated
When one thread runs out of time for context switching, it returns to the ready state and switches to another thread. From saving to reloading a task is called a context switch. Consumes a lot of CPU time.