What happens if I call a java function from multiple threads from C with JNI?

This link seems to suggest that โ€œit just worksโ€: (quite far below at the bottom 7.3 Attaching own threads) http://java.sun.com/docs/books/jni/html/invoke.html

I do not understand how this is possible, is the built-in JVM automatically start its own threads? Or JNI Call Queues? How else can there be several calls to the same virtual machine. which I did not instruct to make a thread?

In any case, I can imagine that there is work if the Java code will simply be executed in the same call flow as the c code. It's right? This would mean that I do not need to do any threads in Java.

+6
source share
2 answers

jvm should not create its own threads; method calls are made in its own threads that create them. AttachCurrentThread and DetachCurrentThread will take care of any proper control of the internal state of jvm, for example, by creating Thread java objects wrapping their own threads.

+4
source

The JVM launches its own threads to be started. You start creating this thread by starting the JVM.

0
source

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


All Articles