NOTE

6.21 Kernel-Level Thread

1. What it is. 2. How to verify that Java threads are kernel-level threads. 2.1. Before running. 2.2. After running.

JavaCreated Updated 1 min readhistorical

This is a historical learning note and may contain outdated or incomplete understanding.

1. What It Is

A user-level thread cannot be perceived by the operating system. It is created and scheduled by the application itself.

A kernel-level thread can be perceived by the operating system and is scheduled by the operating system.

2. How to Verify That Java Threads Are Kernel-Level Threads

Kernel-level threads.

A Java program creates kernel threads by having the JVM call system libraries. Java threads and kernel threads have a 1:1 relationship.

The following demonstrates this:

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. Before Running

2.2. After Running

The number of threads increases noticeably, which means the operating system can perceive them, so they are kernel-level threads.

Discussion

Sign in with GitHub to comment. Discussions are stored as GitHub Issues.View on GitHub