Java Notes - Threads

  • Thread: virtual CPU, code execution, and data processing are composed of three parts
    • create thread
      • implement with subclasses

      • Runnable implementation

    • The main method of the Thread class
    • The higher priority is executed first, and the same level guarantees "first in first out"
    • join: Start another thread to calculate after one thread ends
    • stop Forcefully stop the thread from running
    • The interrupt() method can interrupt the execution of the thread
    • Thread communication:

    • synchronized to ensure thread synchronization
      • direct modifier
      • Statement block synchronization, using the current object as a lock synchronized(lock){}//synchronized code segment
    • wait() makes the thread wait, notify and notifyAll wake up the thread
    • Thread pool: Contains several idle threads ready to run
      • Starting from JDK1.5, the Executor framework has been introduced in the Java Concurrency Library, which includes the interface Executor and its subinterface ExecutorService, as well as the class ThreadPoolExecutor that implements these two interfaces

Guess you like

Origin blog.csdn.net/qq_56061892/article/details/126224492