diff --git a/src/main/java/com/muyu/common/Common.java b/src/main/java/com/muyu/common/Common.java index 727d647..07ca8e7 100644 --- a/src/main/java/com/muyu/common/Common.java +++ b/src/main/java/com/muyu/common/Common.java @@ -26,18 +26,4 @@ public class Common { } }; - public static EventLoopGroup workerGroup = new NioEventLoopGroup(); - - public static void main(String[] args) { - int i = 0; - List strings = JSONObject.parseArray(local_one, String.class); - for (String string : strings) { - int length = string.split(",")[1].length(); - if (length > i){ - i = length; - } - } - System.out.println(i); - } - } diff --git a/src/main/java/com/muyu/common/Config.java b/src/main/java/com/muyu/common/Config.java index e700325..850a6d7 100644 --- a/src/main/java/com/muyu/common/Config.java +++ b/src/main/java/com/muyu/common/Config.java @@ -2,6 +2,8 @@ package com.muyu.common; import com.muyu.pojo.Vehicle; import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.nio.NioEventLoopGroup; /** * netty 核心配置 @@ -18,6 +20,11 @@ public class Config { */ public static final String DATA_PACK_SEPARATOR = "#$&*"; + /** + * 工作组配置 + */ + public static EventLoopGroup workerGroup = new NioEventLoopGroup(); + /** * 通道处理上下文 */ diff --git a/src/main/java/com/muyu/netty/client/NettyClientInit.java b/src/main/java/com/muyu/netty/client/NettyClientInit.java index ea85fba..2040721 100644 --- a/src/main/java/com/muyu/netty/client/NettyClientInit.java +++ b/src/main/java/com/muyu/netty/client/NettyClientInit.java @@ -45,7 +45,7 @@ public class NettyClientInit { try { Bootstrap b = new Bootstrap(); mClientHandler = new NettyClientHandler(); - b.group(Common.workerGroup).channel(NioSocketChannel.class) + b.group(Config.workerGroup).channel(NioSocketChannel.class) // KeepAlive .option(ChannelOption.SO_KEEPALIVE, true) // Handler @@ -89,9 +89,9 @@ public class NettyClientInit { e.printStackTrace(); } finally { //优雅的关闭工作组 - Common.workerGroup.shutdownGracefully(); + Config.workerGroup.shutdownGracefully(); //解决意外关闭的情况,重新创建工作组,新的默认工作组 - Common.workerGroup = new NioEventLoopGroup(); + Config.workerGroup = new NioEventLoopGroup(); } } diff --git a/src/main/resources/templates/index.ftlh b/src/main/resources/templates/index.ftlh index 703757e..8b651e8 100644 --- a/src/main/resources/templates/index.ftlh +++ b/src/main/resources/templates/index.ftlh @@ -649,6 +649,10 @@ $("#vehicleMsgLog").append(msg); } function startNettySendMsg(){ + if ($("#gear").val() == "P"){ + $.modal.msgError("你个憨批,驻车挡跑个锤子!!"); + return; + } nettyMsgTime = setInterval("sendNettySendMsg()", 1000); $.modal.msgSuccess("车辆开始上报") }