mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-05-21 00:25:16 +00:00
perf[net]: 使用性能更高的lazySet(),当我们想对一个原子变量进行修改,而且我们知道这个修改不需要立即对其他线程可见。
This commit is contained in:
@@ -64,7 +64,9 @@ public class SignalBridge {
|
||||
var hash = signalId & SIGNAL_MASK;
|
||||
|
||||
var attachment = signalAttachmentArray.get(hash);
|
||||
if (attachment != null && attachment.getSignalId() == signalId && signalAttachmentArray.compareAndSet(hash, attachment, null)) {
|
||||
if (attachment != null && attachment.getSignalId() == signalId) {
|
||||
// 使用性能更高的lazySet(),当我们想对一个原子变量进行修改,而且我们知道这个修改不需要立即对其他线程可见。
|
||||
signalAttachmentArray.lazySet(hash, null);
|
||||
return attachment;
|
||||
}
|
||||
return signalAttachmentMap.remove(signalId);
|
||||
|
||||
@@ -16,6 +16,7 @@ import com.zfoo.event.manager.EventBus;
|
||||
import com.zfoo.net.router.route.SignalBridge;
|
||||
import com.zfoo.scheduler.util.TimeUtils;
|
||||
import com.zfoo.util.ThreadUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -46,6 +47,7 @@ public class SignalBridgeTest {
|
||||
|
||||
arrayTest();
|
||||
mapTest();
|
||||
Assert.assertEquals(executorSize * count * totalIndex * 4, atomicInteger.get());
|
||||
System.out.println(atomicInteger.get());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user