Operating System - HP-UX
1819576 Members
2880 Online
109603 Solutions
New Discussion

Re: catch alarm in the java native method

 
szhiyong
Frequent Advisor

catch alarm in the java native method

Hi,

I have one java interface, the interface uses java native method to call C code. I try to use "alarm()" in the C program. The code is like :
signal(SIGALRM,sig_alarm);
alarm(3);
call network connection;
alarm(0);
But The program (java interface and C program) terminates after there is alarm signal.The operating system is 10.20 in my workstation.

Would someone please tell me how to catch the alarm signal ?

Thanks a lot!

zhiyong
My life is now asking and learning, I wish It can change into replying and discussing
1 REPLY 1
lassehab
Advisor

Re: catch alarm in the java native method

Hi zhiyong

It's not possible, java supports no signal model in the virtual machine. The JVM uses signals internally for its operation and so native methods should
generally avoid attempting to send signals or install handlers for signals.

In a simple case such as catching a CNTL C and doing a cleanup, it is possible to launch Java from within a Perl script. The Perl script can catch the CNTL C and then signal the JVM by writing to a socket. The application needs to be written so that it is listening on that socket for the signal.

If you have error when you use system handler
You can avoid this error and proceed with process use the following XX HotSpot runtime option:

-XX:+AllowUserSignalHandlers

This JVM option instructs the JVM not to complain if the native code libraries
install signal handlers.

Regards
I love Java OS