简体   繁体   中英

Java app does not start a thread when called from C (JNI) DLL

I've created a java library in which a thread is started.

When testing this library with a normal java-main method and calling the library, the thread in question just starts fine.

But now I want to call this library from a C dll via JNI.

1) So, the C dll calls a library method foo via JNI

2) foo creates a java thread and calls start on it

3) foo returns to the C dll caller.

4) Java thread now starts

The problem is that I get a Future back from the thread and I call get on it.

This get blocks forever when the java code is called from the C dll, but works fine when called from another java app.

All other code is running also fine with JNI.

Any ideas how this can happen?

Is the dll or JNI somehow preventing java thread creation?

In case someone faced a similar problem:

The issue was that I created a native callback to the dll.

This callback is called from the created thread and multithreading on the native code was not allowed.

Removing all calls from the thread to native code solved the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM