java 什么是JVM调度算法?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2816011/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 22:58:39  来源:igfitidea点击:

What is the JVM Scheduling algorithm?

javamultithreadingconcurrencyjvm

提问by mrcaramori

I am really curious about how does the JVM work with threads ! In my searches in internet, I found some material about RTSJ, but I don't know if it's the right directions for my answers. I also found this topic in sun's forums, http://forums.sun.com/thread.jspa?forumID=513&threadID=472453, but that's not satisfatory.

我真的很好奇 JVM 是如何处理线程的!在我在互联网上的搜索中,我找到了一些关于 RTSJ 的材料,但我不知道这是否是我的答案的正确方向。我也在sun 的论坛http://forums.sun.com/thread.jspa?forumID=513&threadID=472453 中找到了这个话题 ,但这并不令人满意。

Can someone give me some directions, material, articles or suggestion about the JVM scheduling algorithm ?

有人能给我一些关于 JVM 调度算法的指导、材料、文章或建议吗?

I am also looking for information about the default configurations of Java threads in the scheduler, like 'how long does it take for every thread' in case of time-slicing. And this stuff.

我也在寻找有关调度程序中 Java 线程默认配置的信息,例如在时间切片的情况下“每个线程需要多长时间”。还有这玩意。

I would appreciate any help !

我将不胜感激任何帮助 !

Thank you !

谢谢 !

回答by Michael Aaron Safyan

There is no single Java Virtual Machine; JVM is a specification, and there are multiple implementations of it, including the OpenJDK version and the Sun version of it, among others. I don't know for certain, but I would guess that any reasonable JVM would simply use the underlying threading mechanism provided by the OS, which would imply POSIX Threads (pthreads) on UNIX (Mac OS X, Linux, etc.) and would imply WIN32 threads on Windows. Typically, those systems use a round-robin strategy by default.

没有单一的 Java 虚拟机;JVM 是一种规范,它有多种实现,包括 OpenJDK 版本和 Sun 版本等。我不确定,但我猜想任何合理的 JVM 都会简单地使用操作系统提供的底层线程机制,这意味着 UNIX(Mac OS X、Linux 等)上的 POSIX 线程(pthreads)并且会暗示 Windows 上的 WIN32 线程。通常,这些系统默认使用循环策略。

回答by Chris Dolan

It doesn't. The JVM uses operating system native threads, so the OS does the scheduling, not the JVM.

它没有。JVM 使用操作系统本机线程,因此操作系统执行调度,而不是 JVM。

回答by Neil Coffey

A while ago I wrote some articles on thread schedulingfrom the point of view of Java. However, on mainstream platforms, threading behaviour essentially depends on underlying OS threading.

前阵子从Java的角度写了一些关于线程调度的文章。然而,在主流平台上,线程行为本质上取决于底层操作系统线程。

Have a look in particular at my page on what is Java thread priority, which explains how Java's priority levels map to underlying OS threading priorities, and how in practice this makes threads of different priorities behave on Linux vs Windows. A major difference discussed is that under Linux there's more of a relationship between thread priority and the proportion of CPU allocated to a thread, whereas under Windows this isn't directly the case (see the graphs).

请特别查看我关于什么是Java 线程优先级的页面,它解释了 Java 的优先级级别如何映射到底层操作系统线程优先级,以及在实践中这如何使不同优先级的线程在 Linux 与 Windows 上的行为。讨论的一个主要区别是,在 Linux 下,线程优先级与分配给线程的 CPU 比例之间有更多的关系,而在 Windows 下,情况并非如此(见图表)。

回答by Rorschach

I don't have commenting rights so writing is here... JVM invokes pthreads(generally used threading mechanism,other variants are there) for each corresponding request. But the scheduling here is done entirely by OS acting as host. But it is a preferred approach and it is possible to schedule these threads by JVM. For example in Jikes RVM there are options to override this approach of OS decision. For example, in it threads are referred as RVMThread and they can be scheduled/manipulated using org.jikesrvm.schedular package classes. For more reference

我没有评论权,所以写作在这里...... JVM 为每个相应的请求调用 pthreads(通常使用的线程机制,还有其他变体)。但是这里的调度完全由充当主机的操作系统完成。但这是一种首选方法,可以通过 JVM 来调度这些线程。例如,在 Jikes RVM 中,有一些选项可以覆盖这种操作系统决策方法。例如,其中的线程被称为 RVMThread,它们可以使用 org.jikesrvm.schedular 包类进行调度/操作。更多参考