tisonkun commented on code in PR #7000:
URL: https://github.com/apache/opendal/pull/7000#discussion_r2616622124


##########
bindings/java/src/executor.rs:
##########
@@ -116,24 +116,45 @@ pub unsafe extern "system" fn 
Java_org_apache_opendal_AsyncExecutor_disposeInter
 }
 
 pub(crate) fn make_tokio_executor(env: &mut JNIEnv, cores: usize) -> 
Result<Executor> {
-    let vm = env.get_java_vm().expect("JavaVM must be available");
+    let vm = Arc::new(env.get_java_vm().expect("JavaVM must be available"));
     let counter = AtomicUsize::new(0);
     let executor = tokio::runtime::Builder::new_multi_thread()
         .worker_threads(cores)
         .thread_name_fn(move || {
             let id = counter.fetch_add(1, Ordering::SeqCst);
             format!("opendal-tokio-worker-{id}")
         })
-        .on_thread_start(move || {
-            ENV.with(|cell| {
-                let mut env = vm
-                    .attach_current_thread_as_daemon()
-                    .expect("attach thread must succeed");
+        .on_thread_start({
+            let vm = vm.clone();
+            move || {
+                ENV.with(|cell| {
+                    let mut env = vm
+                        .attach_current_thread_as_daemon()

Review Comment:
   @rib Thanks for your information! Updated.
   
   Besides, `opendal-java` is glad to give the ongoing `jni` 0.22 an early 
adoption since it is compiled down to `cdylib` for loading from the Java lib, 
rather than being released to crates.io.
   
   I'd appreciate it if you would bump `jni` here so that we can smoothly move 
to 0.22 once it released, or if you're active for help, I can drive this early 
adoption.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to