20165332 Eighth week study summary

20165332 Eighth week study summary

Textbook learning content summary

Chapter 12: Java Multithreading Mechanism
Process and Thread
A thread is a smaller unit than a process. A process can generate multiple threads during its execution. Threads
in Java
Main thread
Each Java application has a default the main thread. When the JVM loads the code and finds the main method, it starts a thread, called the "main thread" (main thread), which is responsible for executing the main method.
The state and life cycle of threads The
Java language uses objects of the Thread class and its subclasses to represent threads
. A newly created thread usually experiences the following four states in its complete life cycle:
1. New: When a Thread class or its When an object of the subclass is declared and created, the new thread object is in the newly created state.
2. Running: The thread must call the start() method (a method inherited from the parent class) to notify the JVM, so that the JVM will know that there is a new thread queued for switching. Once it is its turn to enjoy CPU resources, this thread can start its own life cycle independently of the main thread that created it.
3. Interruption: There are 4 reasons for interruption:
JVM switches CPU resources from the current thread to other threads, so that the thread gives up the right to use the CPU and is in an interrupted state.
While the thread is using CPU resources, the sleep(int millsecond) method is executed to make the current thread go to sleep.
While the thread is using CPU resources, the wait() method is executed.
While the thread is using CPU resources, it executes an operation and enters the blocking state.
4. Death: The thread in the dead state does not have the ability to continue running, freeing the memory allocated to the thread object

Script screenshot

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324711998&siteId=291194637