2

Is there a one to one mapping between Java Thread objects and OS threads (Lightweight processes). That is, if I have a Thread object, can I always identify precisely one associated OS thread, and will I always have the same associated OS thread? In general this is OS and JVM dependent, so I'll restrict the question to Linux with the Oracle and Open JDK JVMs.

What about the cases of sleeping or waiting threads? And the corner cases of threads that have not started running and those that have finished running?

Raedwald
  • 46,613
  • 43
  • 151
  • 237
  • Linux does not really have "LWP"s; all execution threads are a result of calling `clone(2)` with different parameters – fge Jun 15 '13 at 15:22
  • re "can I always identify precisely one associated OS thread" the answer is yes; otherwise `Thread` guarantees could not be honored (think about thread local storage) – fge Jun 15 '13 at 15:25
  • 1
    Java `Thread`s can be , and have been (green threads) implemented without OS threads, so OS threads are not necessary to provide the `Thread` guarantees. – Raedwald Jun 15 '13 at 15:28

1 Answers1

3

Is there a one to one mapping between Java Thread objects and OS threads (

Yes there is, it has been since Java 1.2.

Prior to Java 1.2 a "green threads" model were used which mapped several Java threads to one OS thread.

nos
  • 223,662
  • 58
  • 417
  • 506
  • You certainly could run the JVM with green threads on linux back in the day. – nos Jun 15 '13 at 15:39
  • 2
    @PeterLawrey: AFAIK also on Linux, because the early threading-model on Linux itself was not based on POSIX threads but ... something else with quite heavy setup costs. – A.H. Jun 15 '13 at 15:47
  • See also this answer to a related question: http://stackoverflow.com/a/8569625/545127 – Raedwald Jun 16 '13 at 21:49
  • See also this answer to a related question: http://stackoverflow.com/a/9934747/545127 – Raedwald Jun 16 '13 at 21:53