Multi-threaded learning - basics (8) Explanation of common thread terms

Main thread: The thread spawned by the JVM calling program main().

Current thread: This is a confusing concept. Generally refers to the process obtained by Thread.currentThread().
Background thread: refers to a thread that provides services to other threads, also known as a daemon thread. The garbage collection thread of the JVM is a background thread. The difference between user threads and daemon threads is whether to wait for the main thread to end depending on the end of the main thread
Foreground thread: refers to the thread that accepts the service of the background thread. In fact, the foreground and background threads are linked together, just like the relationship between the puppet and the manipulator behind the scenes. The puppet is the foreground thread, and the manipulator is the background thread. Threads created by foreground threads are also foreground threads by default. Whether a thread is a background thread can be judged and set through the isDaemon() and setDaemon() methods.

Some common methods of thread class: 

  sleep(): Force a thread to sleep for N milliseconds. 
  isAlive(): Determines whether a thread is alive. 
  join(): Wait for the thread to terminate. 
  activeCount(): The number of active threads in the program. 
  enumerate(): Enumerates threads in a program. 
    currentThread(): Get the current thread. 
  isDaemon(): Whether a thread is a daemon thread. 
  setDaemon(): Sets a thread as a daemon thread. (The difference between user threads and daemon threads is whether to wait for the main thread to end depending on the end of the main thread) 
  setName(): Set a name for the thread. 
  wait(): Forces a thread to wait. 
  notify(): Notifies a thread to continue running. 
  setPriority(): Sets the priority of a thread.

Guess you like

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