1. Process
Each independent program is called a process, "in progress", the process has its own independent memory space, if a process to access the memory space of other processes, it can be a virus, the operating system's multitasking is actually the CPU at very small time interval alternately execute multiple programs, Give people the feeling of multiple programs at the same time.
2. Threads
1. Threading is a lightweight process.
2. The thread does not have a separate memory space.
3. Threads are generated by processes, parasitic on processes.
4. A process can have multiple threads (which is what we call multithreaded programming)
3. Status of the thread
1. New state: A new Thread object was created.
2. Ready state (Runnable): After the object is created, other threads call the object's start () method. The state of the thread is located in a pool of running threads that becomes operational and waits for the CPU to be used.
3. Running state (Running): The ready state of the thread gets the CPU, executes the program code
4. Blocking state (Blocked): The thread has abandoned the use of the CPU for some reason, and temporarily stopped running. Until the thread is in a ready state, the opportunity to go to the running state is reached. There are three kinds of blocking conditions.
A. Waiting for blocking: The running thread executes the wait () method, and the JVM puts the thread into the waiting pool
B. Synchronous blocking: When a running thread acquires a synchronization lock on an object, if the synchronization lock is occupied by another thread, the JVM puts the thread into the lock pool
C. Other blocking: The running thread executes the sleep () or join () method, or when an I/O request is made, the JVM will place the thread in a blocked state. When the sleep () state times out, join () waits for the thread to terminate or time out, or the I/O process finishes, the thread is re-entered in a ready state.
5. Death status (Dead): The thread has finished executing or exited the run () method due to an exception. End the life cycle.
java-multithreaded Programming < three >