开发者

How to send events/signal from C to Java in JNI

Is there any mechanism to send asynchronous events/signals through JNI from C to Java开发者_Go百科 or viceversa? I need to catch a signal/event from C to Java.


It sounds a bit tricky, as JNI is supposed to be one-way only: Java code can invoke a native method, which of course may call back into Java code, but can't itself initiate the process.

But it isn't impossible, I think the most straightforward solution is to have a native call that blocks until the signal is received.

Another option would be to write a JVMTI agent, which can interfere with a running VM actively.

But if we're talking about UNIX signals, you can handle then with the not public API (therefore not guaranteed in the future and Sun VM specific) but existing sun.misc.Signal class.


You can call a Java method from C code. See the JNI documentation. See also http://journals.ecs.soton.ac.uk/java/tutorial/native1.1/implementing/method.html.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜