Skip to content

Commit 6067ba6

Browse files
committed
support async startup netty server
1 parent 48d84fa commit 6067ba6

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/main/java/cn/ipman/cache/CacheManApplication.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
import org.springframework.boot.SpringApplication;
44
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.scheduling.annotation.EnableAsync;
56

67
@SpringBootApplication
8+
@EnableAsync
79
public class CacheManApplication {
810

911
public static void main(String[] args) {

src/main/java/cn/ipman/cache/server/IMCacheServer.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@
22

33
import io.netty.bootstrap.ServerBootstrap;
44
import io.netty.buffer.PooledByteBufAllocator;
5-
import io.netty.channel.Channel;
6-
import io.netty.channel.ChannelInitializer;
7-
import io.netty.channel.ChannelOption;
8-
import io.netty.channel.EventLoopGroup;
5+
import io.netty.channel.*;
96
import io.netty.channel.epoll.EpollChannelOption;
107
import io.netty.channel.nio.NioEventLoopGroup;
118
import io.netty.channel.socket.SocketChannel;
129
import io.netty.channel.socket.nio.NioServerSocketChannel;
1310
import io.netty.handler.logging.LogLevel;
1411
import io.netty.handler.logging.LoggingHandler;
1512
import io.netty.util.concurrent.DefaultThreadFactory;
13+
import org.springframework.scheduling.annotation.Async;
1614
import org.springframework.stereotype.Component;
1715

1816
/**
@@ -35,6 +33,7 @@ public void init() {
3533
workerGroup = new NioEventLoopGroup(16, new DefaultThreadFactory("redis-work"));
3634
}
3735

36+
@Async
3837
@Override
3938
public void startup() {
4039
try {
@@ -65,8 +64,7 @@ protected void initChannel(SocketChannel ch) {
6564
} catch (Exception e) {
6665
throw new RuntimeException(e);
6766
} finally {
68-
bossGroup.shutdownGracefully();
69-
workerGroup.shutdownGracefully();
67+
shutdown();
7068
}
7169
}
7270

0 commit comments

Comments
 (0)