NOTE

6.21 Kernel_level_thread

1. 是什么 User level thread是操作系统感知不到的,由应用程序自己创建的线程并负责调度 Kernel level thread是操作系统能感知到的,并由操作系统负责调度 2. 如何验证Java线程是kernel级别的 Kernel level thread. Java程序通过JVM

Java创建于 更新于 historical

这是历史学习笔记,可能存在过时或不完整的理解。

1. 是什么

User level thread是操作系统感知不到的,由应用程序自己创建的线程并负责调度 Kernel level thread是操作系统能感知到的,并由操作系统负责调度

2. 如何验证Java线程是kernel级别的

Kernel level thread. Java程序通过JVM调用系统库创建内核线程,Java线程和内核线程是1:1的关系 证明如下:

public class KernelLevelThread
{
    public static void main(String[] args) throws InterruptedException
    {
        CountDownLatch latch = new CountDownLatch(500);
        for (int i = 0; i < 500; i++)
        {
            new Thread(()->{
                try
                {
                    TimeUnit.SECONDS.sleep(10L);
                    latch.countDown();
                }
                catch (InterruptedException e)
                {
                    e.printStackTrace();
                }
            }).start();
        }

        latch.await();
    }
}

2.1. 运行前

2.2. 运行后

线程数明显增加,说明操作系统感知到了,所以是kernel level thread