diff --git a/bindings/java/Cargo.toml b/bindings/java/Cargo.toml index ba2b8848e2c..e9b27e5683a 100644 --- a/bindings/java/Cargo.toml +++ b/bindings/java/Cargo.toml @@ -157,7 +157,6 @@ services-yandex-disk = ["opendal/services-yandex-disk"] [dependencies] anyhow = "1.0.71" jni = "0.21.1" -num_cpus = "1.15.0" once_cell = "1.19.0" # this crate won't be published, we always use the local version opendal = { version = ">=0", path = "../../core", features = [ diff --git a/bindings/java/src/executor.rs b/bindings/java/src/executor.rs index 4c423b06bed..1ce861c3030 100644 --- a/bindings/java/src/executor.rs +++ b/bindings/java/src/executor.rs @@ -18,6 +18,8 @@ use std::cell::RefCell; use std::ffi::c_void; use std::future::Future; +use std::num::NonZeroUsize; +use std::thread::available_parallelism; use jni::objects::JClass; use jni::objects::JObject; @@ -152,5 +154,10 @@ pub(crate) fn executor_or_default<'a>( /// /// This function could be only when the lib is loaded. unsafe fn default_executor<'a>(env: &mut JNIEnv<'a>) -> Result<&'a Executor> { - RUNTIME.get_or_try_init(|| make_tokio_executor(env, num_cpus::get())) + RUNTIME.get_or_try_init(|| { + make_tokio_executor( + env, + available_parallelism().map(NonZeroUsize::get).unwrap_or(1), + ) + }) }