Linux 上的实时 Java 线程和操作系统级线程
当使用实时 Java 线程(RealtimeThread
或 NoHeapRealtimeThread
)时,操作系统级线程和 Java 线程之间是否存在 1 对 1 的关系?另外,Java 是否为在操作系统级别创建的每个进程使用 fork() 或 clone() ?
When using real time java threads (either RealtimeThread
or NoHeapRealtimeThread
), is there a 1 to 1 relationship between OS Level threads and Java threads? Also, is Java using fork() or clone() for each of the processes created at the OS Level?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Linux 上的 Java 线程取决于版本,但大多数现代实现都使用 pthread,即 Linux 的线程,而不是真正的进程。 Linux线程也被称为轻量级进程,它不是由fork调用生成的,而是由pthread调用生成的。线程运行在同一个进程下,可以共享一定的资源。
是的,它们是一对一的关系,(ps -Lf),但是很难找出哪个是哪个,因为操作系统线程 ID 是一个只有 jvm 知道的神奇数字。
下面的文章应该有所帮助。
http://linuxprograms。 wordpress.com/2007/12/19/linux-kernel-support-for-threads-light-weight-processe/
Java thread on linux depends on the version, but most modern implementations use pthread, the thread for linux, not really a process. the linux thread is also know as lightweight processes, which is not generated by an fork call, but rather the pthread call. Threads run under the same process, and can share certain resources.
Yes they are of 1 to 1 relationship, (ps -Lf), but it is really hard to find out which is which, as the os thread id is an magic number only the jvm knows.
The article below should help.
http://linuxprograms.wordpress.com/2007/12/19/linux-kernel-support-for-threads-light-weight-processe/
如果您指的是由 Runtime.exec() 创建的进程,则它必须使用 fork()。如果您仍然引用线程,则它不能使用 fork(),因为线程不是进程。
If you mean processes created by Runtime.exec(), it must use fork(). If you are still referring to threads it cannot use fork(), as threads are not processes.
从我在带有 Sun/Oracle JVM 的 RedHat 3.x - 5.x 上看到的情况来看,每个 Java 线程只有一个操作系统进程。但不知道分叉与克隆。
From what I have seen on a RedHat 3.x - 5.x with Sun/Oracle JVM, It's a one OS process per Java thread. Don't know about fork vs. clone though.