You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by xu...@apache.org on 2024/08/31 16:46:07 UTC
(opendal) branch main updated: refactor(bindings/java): replace `num_cpus` with `std::thread::available_parallelism` (#5080)
This is an automated email from the ASF dual-hosted git repository.
xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opendal.git
The following commit(s) were added to refs/heads/main by this push:
new d71bd8ee72 refactor(bindings/java): replace `num_cpus` with `std::thread::available_parallelism` (#5080)
d71bd8ee72 is described below
commit d71bd8ee72d2cc497c266bd6aee30d62f4f104e4
Author: miro <hi...@miro.im>
AuthorDate: Sun Sep 1 00:46:02 2024 +0800
refactor(bindings/java): replace `num_cpus` with `std::thread::available_parallelism` (#5080)
refactor(bindings/java): replace num_cpus with std available_parallelism
---
bindings/java/Cargo.toml | 1 -
bindings/java/src/executor.rs | 9 ++++++++-
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/bindings/java/Cargo.toml b/bindings/java/Cargo.toml
index ba2b8848e2..e9b27e5683 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 4c423b06be..1ce861c303 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),
+ )
+ })
}