How JVM thread scheduler control threads for multiprocessors?

前端 未结 3 696
感动是毒
感动是毒 2020-12-31 12:38

I\'ve been reading Head First for multithreading. What I know about multithreading is:

When we call start() with an object of Thread

3条回答
  •  半阙折子戏
    2020-12-31 12:52

    As the others answered correctly, JVM uses the underlying OS (Windows 10 in my case) to manage threads. The windows OS will do pre-emptive (priority-based) scheduling. If there exists multiple threads with Highest priority, windows will use round-robin based time-slicing scheduling for the threads.

    ( Reference:- https://docs.microsoft.com/en-us/windows/win32/procthread/scheduling-priorities )

    To answer the specific question about the multi-processor systems (windows again here as OS), it depends on the architecture such a system is using. Typically there are 2 types of architecture

    1. NUMA - Non Uniform Memory Access
    2. SMP - Symmetric Multi-Processing

    In case of NUMA, the thread is assigned to a processor which is closer (physically) to the memory being used. Because, that way the memory access is faster.

    However, in an SMP computer, two or more identical processors or cores connect to a single shared main memory. Essentially, it is like running things on a single integrated processor. Here, we cannot guarantee which processor the thread will be assigned to.

    You can also specify a thread to execute on a particular processor by setting the "ThreadAffinity" or the "Thread Ideal Processor" property.

    ( Reference:- https://docs.microsoft.com/en-us/windows/win32/procthread/multiple-processors ).

    Hope this helps !! Cheers !!

提交回复
热议问题