Are Java threads created in user space or kernel space? Are Java threads created in user space or kernel space? multithreading multithreading

Are Java threads created in user space or kernel space?


Java threads are "user" threads, but under the hood, the Java Virtual Machine is using kernel threads and delegating the user threads CPU time on each kernel thread in its kernel thread pool. See this question for a better explanation. It seems that threading is JVM-vendor specific, and my understanding might not hold for all JVM implementations.


Most JVMs implement threads with native, OS level threads, including the Oracle reference implementation based on OpenJDK.

I imagine the JVMs that use 'green threads' (user space simulation of threads) would use preemptive scheduling so that an infinite loop in one thread doesn't block the other threads, but without knowledge of a particular implementation this is just speculation.


Java threads are user threads for sure but eventually they're mapped to kernel-level threads before getting executed for real. This mapping probably depends on particular JVM implementation (or the mapping model).

Scheduling wise, kernel threads are scheduled at the os level by an alarm clock that interrupts the kernel periodically. IMO, when that happens, your JVM thread(potentially multiple) may get to execute it's code, or may spawn another thread (which could cause the os to create another kernel thread or block it depending on the mapping model), or may run it's own particular scheduling algorithm to decide which thread which were previously blocked on the same lock will be context-switched next etc.