This is an automated email from the ASF dual-hosted git repository.
chaokunyang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/fury.git
The following commit(s) were added to refs/heads/main by this push:
new 027ddaad fix(java): fix add fury thread safety issue (#1889)
027ddaad is described below
commit 027ddaadf9fe6160d9f01deb304afc7f6817bd41
Author: Shawn Yang <[email protected]>
AuthorDate: Thu Oct 17 20:14:36 2024 +0800
fix(java): fix add fury thread safety issue (#1889)
## What does this PR do?
fix add fury thread safety issue
<!-- Describe the purpose of this PR. -->
## Related issues
#1840
## Does this PR introduce any user-facing change?
<!--
If any user-facing interface changes, please [open an
issue](https://github.com/apache/fury/issues/new/choose) describing the
need to do so and update the document if necessary.
-->
- [ ] Does this PR introduce any public API change?
- [ ] Does this PR introduce any binary protocol compatibility change?
## Benchmark
<!--
When the PR has an impact on performance (if you don't know whether the
PR will have an impact on performance, you can submit the PR first, and
if it will have impact on performance, the code reviewer will explain
it), be sure to attach a benchmark data here.
-->
---
java/fury-core/src/main/java/org/apache/fury/ThreadLocalFury.java | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/java/fury-core/src/main/java/org/apache/fury/ThreadLocalFury.java
b/java/fury-core/src/main/java/org/apache/fury/ThreadLocalFury.java
index d742650d..e45453bb 100644
--- a/java/fury-core/src/main/java/org/apache/fury/ThreadLocalFury.java
+++ b/java/fury-core/src/main/java/org/apache/fury/ThreadLocalFury.java
@@ -21,6 +21,8 @@ package org.apache.fury;
import java.io.OutputStream;
import java.nio.ByteBuffer;
+import java.util.Collections;
+import java.util.Map;
import java.util.WeakHashMap;
import java.util.function.Consumer;
import java.util.function.Function;
@@ -45,11 +47,11 @@ public class ThreadLocalFury extends AbstractThreadSafeFury
{
private final ThreadLocal<LoaderBinding> bindingThreadLocal;
private Consumer<Fury> factoryCallback;
- private final WeakHashMap<LoaderBinding, Object> allFury;
+ private final Map<LoaderBinding, Object> allFury;
public ThreadLocalFury(Function<ClassLoader, Fury> furyFactory) {
factoryCallback = f -> {};
- allFury = new WeakHashMap<>();
+ allFury = Collections.synchronizedMap(new WeakHashMap<>());
bindingThreadLocal =
ThreadLocal.withInitial(
() -> {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]