AsyncConnection优化

This commit is contained in:
redkale
2023-07-04 19:09:29 +08:00
parent 81e871cca9
commit 5390147985
2 changed files with 19 additions and 17 deletions

View File

@@ -298,23 +298,25 @@ abstract class AsyncNioConnection extends AsyncConnection {
this.clientModeWriteQueue.offer(data);
this.writeCompletionHandler = (CompletionHandler) handler;
this.writeAttachment = attachment;
if (writeKey == null) {
ioWriteThread.register(selector -> {
try {
if (writeKey == null) {
writeKey = implRegister(selector, SelectionKey.OP_WRITE);
writeKey.attach(this);
} else {
writeKey.interestOps(writeKey.interestOps() | SelectionKey.OP_WRITE);
try {
if (writeKey == null) {
ioWriteThread.register(selector -> {
try {
if (writeKey == null) {
writeKey = implRegister(selector, SelectionKey.OP_WRITE);
writeKey.attach(this);
} else {
writeKey.interestOps(writeKey.interestOps() | SelectionKey.OP_WRITE);
}
} catch (ClosedChannelException e) {
handleWrite(0, e);
}
} catch (ClosedChannelException e) {
this.writeCompletionHandler = (CompletionHandler) handler;
this.writeAttachment = attachment;
handleWrite(0, e);
}
});
} else {
ioWriteThread.interestOpsOr(writeKey, SelectionKey.OP_WRITE);
});
} else {
ioWriteThread.interestOpsOr(writeKey, SelectionKey.OP_WRITE);
}
} catch (Exception e) {
handleWrite(0, e);
}
}

View File

@@ -1430,7 +1430,7 @@ public final class CacheMemorySource extends AbstractCacheSource {
}
CacheEntry entry = container.get(key);
if (entry == null || !entry.isSetCacheType() || entry.csetValue == null) {
Set set = cacheType == CacheEntryType.SET_SORTED ? Collections.synchronizedSet(new TreeSet<>()) : new CopyOnWriteArraySet();
Set set = cacheType == CacheEntryType.SET_SORTED ? new ConcurrentSkipListSet<>() : new CopyOnWriteArraySet();
entry = new CacheEntry(cacheType, key, null, set, null, null);
CacheEntry old = container.putIfAbsent(key, entry);
if (old != null) {