Memset(msgq.msg_text,0,sizeof(msgq.msg_text)) If(pthread_create(&pid2,NULL,snd_pthread,(void *)(long)msqid)!=0) If(pthread_create(&pid1,NULL,recv_pthread,(void *)(long)msqid)!=0) If ( ( msqid = msgget ( key, IPC_CREAT | 0666 ) ) = -1 ) String msr = new String ( buf, 0, len ) Receive message, receive type is defined as 9528 Send message, the sending type is defined as 9527 System.load("/home/xd/Documents/java_workspace/jni/jni_lib/MsgQ.so") Because the message queue is blocking receiving, it is necessary to use multithreading to send and receive messages. Write the function according to h file 5. Public native static int msgrcv ( int msqid, byte msg, int len, int type ) Ĥ. Public native static int msgsnd ( int msqid, int type, byte msg, int len ) Public native static int msgget ( int msg_key ) Readmslen = msgrcv ( msqid, &msgq, MSG_MAX, mstype, 0 ) 3. The process of writing data to the formation is similar to adding data to the tail of the chain list, and taking data is equivalent to taking data from the head of the chain. The process creates a message queue in the kernel through the agreed key value, and the corresponding key returns the qid of the message queue. ![]() ![]() Jint left = env->GetIntField(obj, id_field) ģ, Creating local message queue through JNI 1. JfieldID id_field = env->GetFieldID(clazz, "id", "I") public class JNIDemo Field(jobject obj, jfieldID fieldID, NativeType value)Įxample: jclass clazz = env->FindClass("Path name") home/xd/Documents/java_workspace/jni/jni_lib is the directory to store the dynamic link library of local methods used by this class. Because of the memory management of JVM, java needs native method to create shared memory and message queue in linux memory to communicate with other processes on the operating system.Įnvironment: centos7, jni, java 1, Basic process of JNI programming 1. ![]() The process written in local C language needs to interact with the process written in java, and the way of using shared memory and message queue is more efficient.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |