Sun JVM 如何将 Java 线程映射到 Windows 线程?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/258901/
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-09-15 11:33:03  来源:igfitidea点击:

How does the Sun JVM map Java threads to Windows threads?

javawindowsmultithreadingjvm

提问by David Kerr

My application uses loads of Java threads. I am looking for a reliable understanding how the JVM (version 5 and 6) maps the Java threads to underlying Windows threads. I know there is a document for mapping to Solaris threads, but not Windows.

我的应用程序使用大量 Java 线程。我正在寻找对 JVM(版本 5 和 6)如何将 Java 线程映射到底层 Windows 线程的可靠理解。我知道有一个文件可以映射到 Solaris 线程,但不是 Windows。

Why doesn't Sun publish this information?

Sun 为什么不发布这些信息?

I want to know if there's a 1:1 mapping, or if it varies by JVM, by -server option, by workload, etc, etc.

我想知道是否存在 1:1 映射,或者它是否因 JVM、-server 选项、工作负载等而异。

I know I am not "supposed" to care, I should write properly synchronisd code, but I am inheriting a large body of code...

我知道我不“应该”关心,我应该编写正确的同步代码,但我继承了大量代码......

Also, does anyone know how to give names to Windows threads?

另外,有谁知道如何为 Windows 线程命名?

采纳答案by TheMarko

Don't have a document for you, but from the Threads column in the task-manager you can pretty reliably guess that it maps 1:1 to native threads (you need to enable the Threads column in the task manager first).

没有适合您的文档,但从任务管理器中的 Threads 列中,您可以非常可靠地猜测它以 1:1 映射到本地线程(您需要先启用任务管理器中的 Threads 列)。

Oh, almost forgot, you can download the jdk src hereand look yourself.

哦,差点忘了,你可以在这里下载jdk src ,自己看看。

回答by Miguel Ping

The mapping is platform-dependent, however I found an interesting comparisonbetween platform threads for the vm (although probably a bit old). The bottom line is: you don't need to know. What you probably are more interested is to know about green threads(if you don't know already).

映射是平台相关的,但是我发现vm 的平台线程之间的一个有趣的比较(虽然可能有点旧)。底线是:你不需要知道。您可能更感兴趣的是了解绿色线程(如果您还不知道的话)。

As for the naming question: Doesn't the constructorallow you to name a thread? Or do you mean name them and view their name on some windows thread browser?

至于命名问题:构造函数不允许您命名线程吗?或者您的意思是命名它们并在某些 Windows 线程浏览器上查看它们的名称?

回答by MSalters

How to name a Win32 thread

如何命名 Win32 线程

Unfortunately, this seems like it's impossible or at least very hard to do inside the Windows JVM.

不幸的是,这在 Windows JVM 中似乎是不可能或至少很难做到的。

回答by rai.skumar

JVM specification doesn't say anything strictly in this regard. Its left upto the JVM implementors to map Java theads to platform theads( Windows, Linux etc). Also its hard to believe that there will be one to one mapping between Java threads and OS threads.

JVM 规范在这方面没有严格规定。由 JVM 实现者将 Java 主题映射到平台主题(Windows、Linux 等)。也很难相信 Java 线程和 OS 线程之间会有一对一的映射。