20165237 2017-2018-2 "Java Programming" Week 8 Learning Summary

20165237 2017-2018-2 "Java Programming" Week 8 Learning Summary

Textbook learning content summary

1. Program: A piece of static code, which is the blueprint for the execution of application software.

2. Process: A dynamic execution process of a program, which corresponds to a complete process from code loading, execution to execution completion. This process is also the process itself from generation, development to death.

3. Thread: a smaller execution unit than a process. A process can generate multiple threads during its execution, forming multiple execution threads. Each thread, that is, each thread, also has its own generation, existence and death. Process.

4. 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.

5. When the JVM (Java Virtual Machine virtual machine) loads the code and finds the main method, it will start a thread, which is called the "main thread" (main thread), which is responsible for executing the main method. The JVM waits until all threads in the Java application have ended before ending the Java application.

6. The created thread usually goes through the following four states in its complete 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.

  • Dead: A thread in a dead state does not have the ability to continue running. The thread frees the entity.

7. Common methods of threads:

  • start() : When a thread calls this method, it will start the thread and enter the ready queue from the new state. Once it is its turn to enjoy the CPU resources, it can start its own life cycle independently of the thread that created it.

  • run(): The run() method of the Thread class has the same function and function as the run() method in the Runnable interface. Both are used to define the operations performed after the thread object is scheduled, which are automatically called by the system and cannot be referenced by the user program. Methods.

  • sleep(int millsecond): A thread with high priority can call the sleep method in its run() method to make itself give up CPU resources and sleep for a period of time.

  • isAlive(): When the thread is in the "new" state, the thread calls the isAlive() method and returns false. Before the thread's run() method ends, that is, before it enters the dead state, the thread calls the isAlive() method to return true.

  • currentThread(): This method is a class method in the Thread class and can be called with a class name. This method returns the thread that is currently using CPU resources.

  • interrupt() : A thread that occupies CPU resources can let the sleeping thread call the interrupt() method to "wake up" itself, that is, cause the sleeping thread to have an InterruptedException exception, thereby ending the sleep and re-queuing for CPU resources.


Code upload:


code hosting

(screenshot of the running result of the statistics.sh script)


learning progress bar

Lines of code (added/accumulated) Blog volume (new/cumulative) Study time (added/accumulated) important growth
Target 5000 lines 30 articles 400 hours
the first week 80/80 1/1 18/18 Learn to write simple JAVA applications
the second week 357/437 2/3 15/33 Master the use of arrays, symbols, and data
The third week 695/1132 2/5 20/53 Understand the basic structure and construction methods of classes and objects
the fourth week 765/1897 2/7 27/70 Understand subclassing and inheritance, interfaces and implementations
fifth week 1174/3071 2/9 15/85 Learned exception handling and understood the use and characteristics of file streams
Week 6 1175/4186 1/10 18/103 Learn about common utility classes and the generics and collections framework
Week 7 874/5060 3/13 14/117 How to create data sources and master JDBC connections
Week 7 950/6010 2/15 13/130 Understand the multi-threading mechanism of JAVA

Guess you like

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