Thread Context Switch

Article directory


1. Thread Context Switch

因为以下一些原因导致cpu不再执行当前的线程,转换执行另一个线程的代码

  1. The thread's cpu time slice has run out
  2. Garbage collection
  3. There are high priority threads that need to run
  4. The thread itself calls sleep, yield, wait, join, park, synchronized, lock and other methods

当上下文切换时,需要由操作系统保存当前线程的状态,并恢复另一个线程的状态,Java中对应的概念就是程序计数器(Program Counter Register),它的作用是记住下一条jvm指令的执行地址,是线程私有的

  1. The status includes the program counter and information of each stack frame in the virtual machine stack, such as local variables, operand stack, return address, etc.
  2. Frequent occurrence of Context Switch will affect performance

Guess you like

Origin blog.csdn.net/m0_50677223/article/details/130633121