A potential problem of calling Java methods in C program
Source: Internet
Author: User
A potential problem in calling the Java method in C program-Linux general technology-Linux programming and kernel information. The following is a detailed description. JNI provides the interoperability between C and Java programs. Generally, only one JVM instance can be started for each process C. In the project, the Parent and Child processes derived from the C program fork may have the following potential problems:
Condition:
1. a JVM instance is created in the C program.
2. The C program fork the child process.
3. The sub-process calls the Java method and performs some specific operations, such as opening the file stream and not closing; or new apache. or call the toXml method of some JavaBean.
Result:
Sub-processes may be suspended. Use strace to check that the sub-process is blocked in the futex system call.
Futex is a synchronization mechanism in Linux and is introduced in kernel 2.5.7. After testing, for RHEL AS3 (Kernel 2.4), this problem occurs by accident (it is also suspended in the futex system call, so I do not know why futex exists in 2.4 ); this problem occurs almost certainly for RHEL AS4 or Ubuntu 7.10 (Kernel 2.6.
We assume that the synchronization mechanism for file operations in Java conflicts with futex, resulting in a deadlock. The specific causes need to be analyzed. At present, it is necessary to avoid the above operations in the JNI program.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service