JNI - problem with threads and jobject

I have called a native program which creates another thread, which attaches itself to the JVM. Now I want to access the methods of the JVM, but it fails. Here is the code: // // This is the native function that gets called first. // it creates another thread which runs, and also calls the printing-methods in my // java applet. // JNIEXPORT void JNICALL Java_EIGC_1Applet_app_1native_native_1start(JNIEnv* jenv, jobject job) { printAppletConsole(jenv,job,"unused atm"); // save current java VM; // save main applet class; // used by main thread jenv->GetJavaVM(&applet_java_jvm); m_job = job; // create the working and start it applet_thread_main = new EIGC_Applet_thread(&main); applet_thread_main->start(); } // // This is the running thread that was created // This will run and call the printing method in the applet // unsigned __stdcall main(void* args) { // The JNIEnv JNIEnv* jenv = new JNIEnv(); // attach thread to running JVM applet_java_jvm->AttachCurrentThread((void**)jenv,NULL); // main running loop while (true) { Sleep(1000); printAppletConsole(jenv,m_job,"unused"); } applet_thread_main->stop(); return 0; } // // Calls the "writeConsole()" method in applet which prints "test" in a JTextArea // void printAppletConsole(JNIEnv* jenv,jobject job,char* text) { jclass cls = jenv->GetObjectClass(job); jmethodID mid = jenv->GetMethodID(cls,"writeConsole","()V"); if (mid==NULL) { printf("Method not found"); } else { jenv->CallVoidMethod(job,mid); } } I have one question; 1) In the newly created thread, the JVM just hangs when I try to call printAppletConsole, it hangs on the GetObjectClass(). Why is this? My suspicion is that since I have created a new thread, I need to access a new instance of jobject, but Im not sure how.. Thanks!

以上就是JNI - problem with threads and jobject的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏