Skip to content

Commit

Permalink
优化关闭 channel 时机
Browse files Browse the repository at this point in the history
  • Loading branch information
lin1810 committed Jul 27, 2024
1 parent 8371145 commit fda390c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ private void closeChannel(String channelId) {
NettyTcpInstanceClientContext nettyTcpInstanceClientContext =
channel.attr(NettyTcpInstanceClient.CONTEXT_ATTRIBUTE_KEY).get();
if (nettyTcpInstanceClientContext != null
&& nettyTcpInstanceClientContext.getPendingToSendSet().size() > 0) {
&& !nettyTcpInstanceClientContext.getPendingToSendSet().isEmpty()) {
scheduledExecutorService.schedule(() -> closeChannel(channelId), 5, TimeUnit.SECONDS);
} else {
logger.info("close channel({})", channel);
channel.close();
scheduledExecutorService.schedule(() -> {
logger.info("close channel({})", channel);
channel.close();
}, 5, TimeUnit.SECONDS);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@ private void closeChannel(String channelId) {
NettyTcpInstanceContext nettyTcpInstanceContext =
channel1.attr(NettyTcpInstanceHandler.CONTEXT_ATTRIBUTE_KEY).get();
if (nettyTcpInstanceContext != null
&& nettyTcpInstanceContext.getPendingToSendSet().size() > 0) {
&& !nettyTcpInstanceContext.getPendingToSendSet().isEmpty()) {
scheduledExecutorService.schedule(
() -> closeChannel(channelId), 5, TimeUnit.SECONDS);
} else {
logger.info("close channel({})", channelId);
channel1.close();
scheduledExecutorService.schedule(() -> {
logger.info("close channel({})", channelId);
channel1.close();
}, 5, TimeUnit.SECONDS);
}
} else {
logger.debug(
Expand Down

0 comments on commit fda390c

Please sign in to comment.