Skip to content

Commit

Permalink
3
Browse files Browse the repository at this point in the history
  • Loading branch information
youfanx committed Nov 28, 2024
1 parent 9fce94a commit fd5fb21
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 14 deletions.
6 changes: 3 additions & 3 deletions rxlib/src/main/java/org/rx/bean/ConcurrentWeakMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ public class ConcurrentWeakMap<K, V> implements AbstractMap<K, V> {
final boolean identityReference;
transient MapView.EntrySetView<Reference<K>, K, V> entrySet;

public ConcurrentWeakMap() {
this(16, false);
public ConcurrentWeakMap(boolean identityReference) {
this(identityReference, 16);
}

public ConcurrentWeakMap(int initialCapacity, boolean identityReference) {
public ConcurrentWeakMap(boolean identityReference, int initialCapacity) {
map = new ConcurrentHashMap<>(initialCapacity);
this.identityReference = identityReference;
}
Expand Down
7 changes: 2 additions & 5 deletions rxlib/src/main/java/org/rx/core/CpuWatchman.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.rx.bean.DateTime;
import org.rx.bean.Decimal;
import org.rx.bean.IntWaterMark;
import org.rx.bean.Tuple;
import org.rx.bean.*;
import org.rx.exception.InvalidException;
import org.rx.exception.TraceHandler;
import org.rx.util.BeanMapper;
Expand Down Expand Up @@ -162,7 +159,7 @@ static int decrSize(ThreadPoolExecutor pool) {
return poolSize;
}

final Map<ThreadPoolExecutor, Tuple<IntWaterMark, int[]>> holder = new WeakIdentityMap<>(8);
final Map<ThreadPoolExecutor, Tuple<IntWaterMark, int[]>> holder = new ConcurrentWeakMap<>(true, 8);

private CpuWatchman() {
timer.newTimeout(this, RxConfig.INSTANCE.threadPool.samplingPeriod, TimeUnit.MILLISECONDS);
Expand Down
6 changes: 3 additions & 3 deletions rxlib/src/main/java/org/rx/core/IOC.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.apache.commons.collections4.map.ReferenceIdentityMap;
import org.apache.commons.collections4.map.ReferenceMap;
import org.rx.bean.ConcurrentWeakMap;
import org.rx.bean.WeakIdentityMap;
import org.rx.exception.InvalidException;

import java.util.*;
Expand All @@ -17,7 +16,8 @@
@SuppressWarnings(NON_UNCHECKED)
public final class IOC {
static final Map<Class<?>, Object> container = new ConcurrentHashMap<>(8);
static final Map WEAK_KEY_MAP = Collections.synchronizedMap(new WeakHashMap<>());
// static final Map WEAK_KEY_MAP = Collections.synchronizedMap(new WeakHashMap<>());
static final Map WEAK_KEY_MAP = new ConcurrentWeakMap<>(false);
static Map weakValMap, wKeyIdentityMap, wValIdentityMap;

public static <T> boolean isInit(Class<T> type) {
Expand Down Expand Up @@ -94,7 +94,7 @@ public synchronized static <K, V> Map<K, V> weakIdentityMap(boolean weakValue) {
return wValIdentityMap;
}
if (wKeyIdentityMap == null) {
wKeyIdentityMap = new ConcurrentWeakMap<>();
wKeyIdentityMap = new ConcurrentWeakMap<>(true);
}
return wKeyIdentityMap;
}
Expand Down
2 changes: 1 addition & 1 deletion rxlib/src/main/java/org/rx/core/ObjectChangeTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ static Object getTarget(Object sourceObj) {
//endregion

public static final ObjectChangeTracker DEFAULT = new ObjectChangeTracker();
final Map<Object, Map<String, Object>> sources = new ConcurrentWeakMap<>();
final Map<Object, Map<String, Object>> sources = new ConcurrentWeakMap<>(true);
final EventBus bus = EventBus.DEFAULT;

public ObjectChangeTracker() {
Expand Down
4 changes: 2 additions & 2 deletions rxlib/src/main/java/org/rx/net/NetEventWait.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.rx.bean.WeakIdentityMap;
import org.rx.bean.ConcurrentWeakMap;
import org.rx.core.*;
import org.rx.exception.TraceHandler;
import org.rx.io.Bytes;
Expand Down Expand Up @@ -88,7 +88,7 @@ public NetEventWait(@NonNull String group, @NonNull InetSocketAddress multicastE
this.multicastEndpoint = multicastEndpoint;
idString = group + "@" + Integer.toHexString(hashCode());
channel = channels.computeIfAbsent(multicastEndpoint, k -> (NioDatagramChannel) Sockets.udpBootstrap(MemoryMode.LOW, true, c -> {
c.attr(REF).set(Collections.newSetFromMap(new WeakIdentityMap<>()));
c.attr(REF).set(Collections.newSetFromMap(new ConcurrentWeakMap<>(true)));
c.pipeline().addLast(Handler.DEFAULT);
})
.bind(multicastEndpoint.getPort()).addListener((ChannelFutureListener) f -> {
Expand Down

0 comments on commit fd5fb21

Please sign in to comment.