20165326 java eighth week study notes

Week 8 study notes

Summary of knowledge points

1. Processes and threads

  • Process: a dynamic execution process of a program
  • Difference: Difference between process and thread?
  • A process is an independent unit of resource allocation and scheduling, while a thread is the basic unit of CPU scheduling
  • The same process can include multiple threads, and the threads share the resources (registers, stacks, contexts) of the entire process, and one process includes at least one thread.
  • Java's multithreading mechanism. Java has built-in support for multithreading. Our computer can only execute one of the threads at any given time, and the Java Virtual Machine simply switches quickly from one thread to another.
    When there are other threads in the main method, the JVM does not end the Java application until all threads in the Java application have ended.

2. There are three ways to create a thread:

  • Inherit the Thread class to create a thread. If you want to get the current thread object in the program, you can use the method Thread.currentThread(); if you want to return the name of the thread, you can use the method:getName()
  • Implement the Runnableinterface to create a thread
  • Using Callableand Futurecreating threads

3. Thread synchronization: If there are several threads that need to use a method at the same time, in order to avoid confusion, you can use synchronized for decoration. This way, the method can only be called in turn, and no other threads can call the method until the thread that is calling the method has finished using the method.

4. Thread union: During the operation of thread A, if other thread B calls the join() method to join thread A, then thread A will be interrupted immediately, and thread A will not be re-queued until thread B finishes running. If thread B has ended, calling the join() method will have no effect.

5. Daemon thread: The thread is a non-daemon thread by default, and the thread must set whether it is a daemon thread before running. You can call voidsetDaemon(boolean on) to set yourself up as a daemon thread. When all non-daemon threads finish running, daemon threads must end with them.

code hosting

Code cloud link

Summary of last week's topics

1. Typical JDBC program writing sequence: register JDBC Driver → obtain a physical connection with the database → create different types of Statement → execute SQL commands → if there is a result set, process the result set → release resources

2. The executeUpdate() method of Statement will return the int value of whether the update is successful

3. The package java.sql provides the ability to access databases in Java

4. Features of relational database:

  • The data types in the same column are the same, and different data types must be defined in different columns
  • Different columns have no order distinction
  • No two tuples can be exactly the same.
  • There is no difference in the order of different lines

Guess you like

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