Github user xiaozhongwang commented on a diff in the pull request: https://github.com/apache/trafodion/pull/1562#discussion_r187753748 --- Diff: core/sqf/src/tm/tmlib.cpp --- @@ -2817,35 +2833,44 @@ void TMLIB::initialize() // This call has been changed so that the node count includes spare nodes, so // will give the wrong value for iv_node_count. msg_mon_get_node_info(&iv_node_count, MAX_NODES, NULL); - is_initialized(true); + iv_initialized = true; // We don't use gv_tmlib_initialized but set it here just to keep things aligned. gv_tmlib_initialized = true; + initMutex_->unlock(); } - - // ------------------------------------------------------------------- // TMLIB::initJNI // Initialize JNI interface // Only used on demand - if you do this in TMLIB::initialize // it gets called when it may not be used and conflicts with udrserv. // ------------------------------------------------------------------- -void TMLIB::initJNI() +int TMLIB::initJNI() { - int lv_err = 0; - static bool ls_initialized = false; + int lv_err = 0; - //sleep(30); - if (ls_initialized) - return; - - short lv_result = setupJNI(); - if (lv_result) { - fprintf(stderr, "setupJNI returned error %d in TMLIB::initJNI. Exiting.\n", lv_result); - fflush(stderr); - abort(); + if ((lv_err = initJNIEnv()) != 0) + return lv_err; + if (isInitialized()) + return 0; + _tlp_jenv->PopLocalFrame(NULL); + if (javaMethodsInitialized_) + return JavaObjectInterfaceTM::init((char *)hbasetxclient_classname, hbasetxclient_class, TMLibJavaMethods_, JM_LAST_HBASETXCLIENT, javaMethodsInitialized_); + else + { + initMutex_->lock(); + if (javaMethodsInitialized_) { + initMutex_->unlock(); + return JavaObjectInterfaceTM::init((char *)hbasetxclient_classname, hbasetxclient_class, TMLibJavaMethods_, JM_LAST_HBASETXCLIENT, javaMethodsInitialized_); + } + short lv_result = setupJNI(); + if (lv_result) { + fprintf(stderr, "setupJNI returned error %d in TMLIB::initJNI. Exiting.\n", lv_result); + fflush(stderr); + abort(); + } } - + initMutex_->unlock(); --- End diff -- I think it's better moving unlock to else branch. Otherwise, if somebody modify the if branch, and not return, will make a mistake.
---