"Eighth Week Learning Summary"

Textbook content summary

Program: A piece of static code

Process: A dynamic execution process of a program, that is, a complete process from code loading, execution to execution completion.

Thread: A smaller execution unit than a process. A process can generate multiple threads during its execution.

Some memory units (including code and data) in the process can be shared between threads, and the interruption and recovery of threads can save system overhead.

A created thread usually goes through the following four states during its entire life cycle:

New: When an object of the Thread class or its subclasses is declared and created, the new thread object is in the new state.

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.

Interruption: There are 4 reasons for interruption:

(1) The JVM switches the 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.

(2) While the thread is using CPU resources, the sleep(int millsecond) method is executed to make the current thread go to sleep.

(3) The wait() method is executed while the thread is using CPU resources.

(4) While the thread is using CPU resources, it executes an operation and enters the blocking state.

Thread class

Constructor: Thread(Runnable target)

Parameters: The parameter of the constructor is an interface of type Runnable

Instance: To pass an instance of the Runnable interface class to the parameter

[Code hosting] ( https://gitee.com/BESTI-IS-JAVA-2018/20165319GaoJunTian/tree/master/week8 )

Guess you like

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