How are Java threads scheduled in kernel space?

Here is my understanding of Java threads that are scheduled when java starts the thread when calling the start()

api of a class java.lang.Thread

running in modern OS implementations (like solaris 9).

enter image description here The LWP

term kernel thread

is used because the term is commonly used in kernel programming to start a thread.

So, every creation java thread

using java.lang.Thread::start()

api has a 1: 1 map with creation native thread

using pthread_create()

either thr_create()

or CreateThread()

on POSIX, Solaris, Windows platforms respectively. In turn, each native thread

has a 1: 1 map with LWP.

My question is:

1)

Can I say there is no Java thread scheduling policy in user space jvm to schedule java threads anymore based on the 1-1 streaming model in the above diagram?

2) Optional: In a scenario with two cores, does the 2 LWPs (representing each JVM process) have an equal chance of being executed simultaneously (in parallel)?

Note. As a Java beginner, I need this clarity.

+3


source to share


2 answers


The diagram details the inner workings of jvm and how they abstract from the underlying operating system threads to the Java threading model. This is how the JVM works on the above operating systems.

To answer your questions directly:



  • ) Every time you create a thread, you create a thread to control the operating system. The JVM has a layer of abstraction between you and the operating system, so you can work with the same threading model on different systems. In general, for non-optimized java code, the java stream is the OS stream.

  • ) You have no guarantees on parallel execution. Depending on the CPU load, the operating system may need resources where higher priority systems are required. When writing multi-threaded applications, write as if everything that happens outside of the thread is unknown.

If you want to learn more about java's multithreaded model, I recommend this book . This book is old, but it is still relevant. It was written by a Java language architect and it details the Java multithreading model.

0


source


Java Thread Scheduling Policy @ JVM layer can be controlled by the following parameters 1) UseBoundThreads 2) AdjustConcurrency 3) Java Thread Priority.



0


source







All Articles