NOTE

6.21 Kernel-Level Thread

User-level threads are managed by applications, while kernel threads are visible to and scheduled by the operating system. These notes connect the distinction with Java threads.

JavaCreated Updated 1 min readhistorical

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

1. What It Is

The operating system is unaware of a user-level thread. It is created and scheduled by the application itself.

The operating system is aware of a kernel-level thread and schedules it.

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 is aware of them, so they are kernel-level threads.

Discussion

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