20165235 Qi Ying 2018-4 "Java Programming" eighth week study summary
Textbook learning content summary
Operating Systems and Processes
A program is a static piece of code that is the blueprint for application software execution. A process is 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 to development to death.
process and thread
Certain memory units in a process can be shared between threads.
java multithreading mechanism
The Java virtual machine quickly switches control from one thread to another, and these threads will be executed in turn, giving each thread a chance to use CPU resources.
main thread
main
Threads are primarily responsible for executingmain
methods. The threads that are created duringmain
the execution of the method are called other threads in the program.JVM
It is necessary to alternate between the main thread and other threads to ensure that each thread has a chance to useCPU
resources.Thread state and life cycle
java
The language usesThread
objects of classes and their subclasses to represent threads.
-start()
The method notifies the JVM, and the JVM will know that a new thread is queued.sleep(int millsecond)
method to put the current thread to sleep.
-run ()
The method specifies the specific mission of the thread.Thread class
- One way to create a thread is to use the
Thread
class to create the thread object directly. Usually its constructor is used. Using
Runnable
interfaces isThread
more flexible than using subclasses.The relationship between the target object and the thread object
- The target object is completely decoupled from the thread object
target object composition thread
thread synchronization
Several threads use a
synchronized
decorated method. Multiple threads callingsynchronized
the decorated method must obey the synchronization mechanism.thread union
While a thread A occupies CPU resources, it can let other threads call
join()
methods to associate with this thread.
Problems and Solving Processes in Teaching Materials Learning
Question 1: When running Example12_3, the results of each run are inconsistent?
Solution: This problem has not been solved yet, but I personally think that
Thread
the two threads of cat and dog are randomly alternated when using CPU resources. It is uncertain who gets the resources first, so there will be inconsistent results.
Code cloud code link
- code of the week
- Example12_1
- Example12_2
- Example12_3
- Example12_4
- Example12_5
- Example12_6
- Example12_7
- Example12_8
- Example12_9
-
Screenshot of script running:
Summary of last week's exam mistakes
- The ones that belong to the data manipulation language are: insert and update
- Statement's executeUpdate() method returns an int value
- The correct exception is: java.sql.SQLException: result set is exhausted (result set is exhausted or next is not called); java.sql.SQLException: No suitable driver (URL misspelled)
- Which of the following are the methods defined in the ResultSet for Cursor positioning:
next()
beforeFirst()
afterLast()
isBeforeFirst()
relative(int)
comprehension
Through this week's study, we have some understanding of threads. When allocating CPU resources to threads, we can understand transitions between different states.
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 | 31/31 | 1/1 | 20/20 | use of git |
the second week | 373/404 | 2/3 | 18/38 | java basic data syntax |
The third week | 547/920 | 1/4 | 22/60 | Classes and objects and packaging |
the fourth week | 919/1839 | 2/6 | 30/80 | Subclassing and Inheritance, Interfaces and Interface-Oriented Programming |
fifth week | 500/2300 | 3/9 | 20/ 100 | Input and output streams and inner classes |
Week 6 | 300/2600 | 1/10 | 25/125 | Generics and collections framework, common utility classes |
Week 7 | 447/3047 | 3/13 | 25/150 | MySQL database and JDBC |
eighth week | 700/3826 | 3/16 | 25/175 | java multithreading mechanism |