微调
This commit is contained in:
@@ -41,39 +41,39 @@ public class WebSocketService {
|
||||
|
||||
@PostConstruct
|
||||
public void start() {
|
||||
new Thread(() -> {
|
||||
//可以自定义线程的数量
|
||||
bossGroup = new NioEventLoopGroup();
|
||||
// 默认创建的线程数量 = CPU 处理器数量 *2
|
||||
workerGroup = new NioEventLoopGroup();
|
||||
try {
|
||||
ServerBootstrap serverBootstrap = new ServerBootstrap();
|
||||
serverBootstrap.group(bossGroup, workerGroup)
|
||||
.channel(NioServerSocketChannel.class)
|
||||
.handler(new LoggingHandler())
|
||||
//当前连接被阻塞的时候,BACKLOG代表的事 阻塞队列的长度
|
||||
.option(ChannelOption.SO_BACKLOG, 128)
|
||||
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000)
|
||||
|
||||
//设置连接保持为活动状态
|
||||
.childOption(ChannelOption.SO_KEEPALIVE, true)
|
||||
.childHandler(webSocketInitializer);
|
||||
ChannelFuture future = serverBootstrap.bind(port).sync();
|
||||
future.addListener(f -> {
|
||||
if (future.isSuccess()) {
|
||||
System.out.println("webSocket服务启动成功");
|
||||
} else {
|
||||
System.out.println("webSocket服务启动失败");
|
||||
}
|
||||
});
|
||||
future.channel().closeFuture().sync();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
bossGroup.shutdownGracefully();
|
||||
workerGroup.shutdownGracefully();
|
||||
}
|
||||
}).start();
|
||||
// new Thread(() -> {
|
||||
// //可以自定义线程的数量
|
||||
// bossGroup = new NioEventLoopGroup();
|
||||
// // 默认创建的线程数量 = CPU 处理器数量 *2
|
||||
// workerGroup = new NioEventLoopGroup();
|
||||
// try {
|
||||
// ServerBootstrap serverBootstrap = new ServerBootstrap();
|
||||
// serverBootstrap.group(bossGroup, workerGroup)
|
||||
// .channel(NioServerSocketChannel.class)
|
||||
// .handler(new LoggingHandler())
|
||||
// //当前连接被阻塞的时候,BACKLOG代表的事 阻塞队列的长度
|
||||
// .option(ChannelOption.SO_BACKLOG, 128)
|
||||
// .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000)
|
||||
//
|
||||
// //设置连接保持为活动状态
|
||||
// .childOption(ChannelOption.SO_KEEPALIVE, true)
|
||||
// .childHandler(webSocketInitializer);
|
||||
// ChannelFuture future = serverBootstrap.bind(port).sync();
|
||||
// future.addListener(f -> {
|
||||
// if (future.isSuccess()) {
|
||||
// System.out.println("webSocket服务启动成功");
|
||||
// } else {
|
||||
// System.out.println("webSocket服务启动失败");
|
||||
// }
|
||||
// });
|
||||
// future.channel().closeFuture().sync();
|
||||
// } catch (InterruptedException e) {
|
||||
// e.printStackTrace();
|
||||
// } finally {
|
||||
// bossGroup.shutdownGracefully();
|
||||
// workerGroup.shutdownGracefully();
|
||||
// }
|
||||
// }).start();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user