The relationship between a Java thread and OS threads

As you know, Java threads can interact using some thread APIs. But I want to know how Java threads and OS threads communicate with each other. For example, a Java thread must wait for some OS thread to complete execution and return some results to this Java thread, and it processes the same.

+3
source share
3 answers

Many mix threads and processes here, jvm is a process that can spawn more threads. Topics are lighter processes that exchange memory as part of their process. A process, on the other hand, lives in its own address space, which makes context switching more expensive. You can communicate between different processes using the IPC mechanisms provided by your OS, and you can communicate between different threads within the same process due to shared memory and other methods. What you cannot do is related to ThreadA (ProcessA) with ThreadA (ProcessB) without going through the normal old IPC:ThreadA(ProcessA) -> ProcessA -> IPC(OS) -> ProcessB -> ThreadA(ProcessB)).

You can use RMI to communicate between two java processes, if you want to "talk" with OS-based processes, you must go JNI to invoke the IPC mechanisms your OS chooses.

:)

Sidenote: JVM ( JVM , , ), jps jstack .

+6

JVM , , .

0

Java- , , Java concurrency , .

If you needed to synchronize between your own thread and a Java thread, you will most likely have to think about writing a JNI method that calls your Java thread. This JNI method will perform any synchronization operation of its own that it must perform and then return. Each platform will do it differently, but I assume that it will not be too big a problem if you need to check your own threads first.

-1
source

Source: https://habr.com/ru/post/1765027/


All Articles