From d2e1f7d907d9cb585170a2a5ea700ca843ab5fe1 Mon Sep 17 00:00:00 2001 From: ahxiao Date: Tue, 26 Sep 2023 18:12:38 +0800 Subject: [PATCH] [summary] reslove performance problem of detach [detail] replace attachCurrentThread with daemon, so the jvm would not wait for detach when exit --- .../src/main/c/jni/org_fisco_bcos_sdk_jni_rpc_RpcJniObj.cpp | 5 +---- .../c/jni/org_fisco_bcos_sdk_jni_rpc_RpcServiceJniObj.cpp | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/bindings/java/jni/src/main/c/jni/org_fisco_bcos_sdk_jni_rpc_RpcJniObj.cpp b/bindings/java/jni/src/main/c/jni/org_fisco_bcos_sdk_jni_rpc_RpcJniObj.cpp index ff34cb9de..36fb232cd 100644 --- a/bindings/java/jni/src/main/c/jni/org_fisco_bcos_sdk_jni_rpc_RpcJniObj.cpp +++ b/bindings/java/jni/src/main/c/jni/org_fisco_bcos_sdk_jni_rpc_RpcJniObj.cpp @@ -24,7 +24,7 @@ static void on_receive_rpc_response(struct bcos_sdk_c_struct_response* resp) delete context; JNIEnv* env; - jvm->AttachCurrentThread((void**)&env, NULL); + jvm->AttachCurrentThreadAsDaemon((void**)&env, NULL); std::string className = "org/fisco/bcos/sdk/jni/common/Response"; std::string onRespSig = "(Lorg/fisco/bcos/sdk/jni/common/Response;)V"; @@ -108,9 +108,6 @@ static void on_receive_rpc_response(struct bcos_sdk_c_struct_response* resp) // release callback global reference env->DeleteGlobalRef(jcallback); - - // detach current thread when job finished - jvm->DetachCurrentThread(); } /* diff --git a/bindings/java/jni/src/main/c/jni/org_fisco_bcos_sdk_jni_rpc_RpcServiceJniObj.cpp b/bindings/java/jni/src/main/c/jni/org_fisco_bcos_sdk_jni_rpc_RpcServiceJniObj.cpp index 9ec5ea0d4..d749e4cb7 100644 --- a/bindings/java/jni/src/main/c/jni/org_fisco_bcos_sdk_jni_rpc_RpcServiceJniObj.cpp +++ b/bindings/java/jni/src/main/c/jni/org_fisco_bcos_sdk_jni_rpc_RpcServiceJniObj.cpp @@ -25,7 +25,7 @@ static void on_receive_tars_rpc_response(struct bcos_sdk_c_struct_response* resp delete context; JNIEnv* env; - jvm->AttachCurrentThread((void**)&env, NULL); + jvm->AttachCurrentThreadAsDaemon((void**)&env, NULL); std::string className = "org/fisco/bcos/sdk/jni/common/Response"; std::string onRespSig = "(Lorg/fisco/bcos/sdk/jni/common/Response;)V"; @@ -109,9 +109,6 @@ static void on_receive_tars_rpc_response(struct bcos_sdk_c_struct_response* resp // release callback global reference env->DeleteGlobalRef(jcallback); - - // detach current thread when job finished - jvm->DetachCurrentThread(); } /*