JNI local thread into layer C

Source: Internet
Author: User

In JNI development, it is sometimes encountered in the case of creating small threads on Layer c. In essence, Java threads and C threads are all request Kerner, just a sequence of executions. From this point of view, threads are no different, Java threads and C threads can be common.


However, there is a special place in the JNI mechanism in which each Java thread assigns a JNIEnv object to the C layer when it accesses it by JNI, and each thread is given a exclusive access. This object is used to request the VM, so it is necessary to operate the Java layer and go to the Java layer. For a thread created on the local C layer, the JNIEnv object is not given a jni, how does it communicate with the Java layer?

The answer is to register a JNIEnv object directly with the VM through the VM pointer. The code is as follows:

Jvm->attachcurrentthread (&env,null);

To create a thread code locally:

Pthread T_thread;
void *trrun (void *)
{//code}
int th1 = Pyhread_create (&t_thread,null,trrun,null);

JNI local thread into layer C

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.