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,6 +298,7 @@ abstract class AsyncNioConnection extends AsyncConnection {
this.clientModeWriteQueue.offer(data); this.clientModeWriteQueue.offer(data);
this.writeCompletionHandler = (CompletionHandler) handler; this.writeCompletionHandler = (CompletionHandler) handler;
this.writeAttachment = attachment; this.writeAttachment = attachment;
try {
if (writeKey == null) { if (writeKey == null) {
ioWriteThread.register(selector -> { ioWriteThread.register(selector -> {
try { try {
@@ -308,14 +309,15 @@ abstract class AsyncNioConnection extends AsyncConnection {
writeKey.interestOps(writeKey.interestOps() | SelectionKey.OP_WRITE); writeKey.interestOps(writeKey.interestOps() | SelectionKey.OP_WRITE);
} }
} catch (ClosedChannelException e) { } catch (ClosedChannelException e) {
this.writeCompletionHandler = (CompletionHandler) handler;
this.writeAttachment = attachment;
handleWrite(0, e); handleWrite(0, e);
} }
}); });
} else { } else {
ioWriteThread.interestOpsOr(writeKey, SelectionKey.OP_WRITE); ioWriteThread.interestOpsOr(writeKey, SelectionKey.OP_WRITE);
} }
} catch (Exception e) {
handleWrite(0, e);
}
} }
public void doRead(boolean direct) { public void doRead(boolean direct) {

View File

@@ -1430,7 +1430,7 @@ public final class CacheMemorySource extends AbstractCacheSource {
} }
CacheEntry entry = container.get(key); CacheEntry entry = container.get(key);
if (entry == null || !entry.isSetCacheType() || entry.csetValue == null) { 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); entry = new CacheEntry(cacheType, key, null, set, null, null);
CacheEntry old = container.putIfAbsent(key, entry); CacheEntry old = container.putIfAbsent(key, entry);
if (old != null) { if (old != null) {