Is there any mechanism to send asynchronous events/signals through JNI from C to Java or viceversa? I need to catch a signal/event from C to Java.
Is there any mechanism to send asynchronous events/signals through JNI from C to Java
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.Signalclass.