4

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?

rreyes1979
  • 1,855
  • 3
  • 23
  • 34

3 Answers3

2

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/

user658991
  • 566
  • 3
  • 7
0

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.

user207421
  • 305,947
  • 44
  • 307
  • 483
-1

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.

Olaf
  • 6,249
  • 1
  • 19
  • 37
  • 1
    I think you might be confused by what `ps` is telling you. It is certainly NOT one "process" per thread because processes don't share address spaces. (And no ... Java doesn't use shared memory to do this either.) – Stephen C May 09 '11 at 02:39
  • 1
    *some* people have called threads light-weight processes, but that is to distinguish them from regular (heavy-weight) processes. The correct (1) term is OS or native thread ... and if you start calling them processes, people will get confused. (1 Correct == what the OS documentation calls them ...) – Stephen C May 09 '11 at 23:02