When using real time java threads (either Realt开发者_C百科imeThread
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?
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/
is Java using fork() or clone() for each of the processes created at the OS Level?
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.
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.
精彩评论