1 握手拦截器 打印时间过长
@Service
@Slf4j
public class SocketInterceptor implements HandshakeInterceptor {/*** socket握手拦截** @param request* @param response* @param wsHandler* @param attributes* @return boolean* @throws Exception*/@Overridepublic boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Map<String, Object> attributes) throws Exception {
// if(!SystemConstants.SYSTEM_INIT_SUCCESS){
// return false;
// }log.error("开始握手 {}", LocalDateTime.now());HttpServletRequest servletRequest = ((ServletServerHttpRequest) request).getServletRequest();//获取tokenString token = servletRequest.getHeader("authorization");if (StringUtils.isBlank(token)){return false;}//检查是否登录了SystemUserDetails userTokenInfoVo = AuthUtil.getLoginUser();if(userTokenInfoVo==null){return false;}//终端类型String clientType = SocketUtil.getClientTypeByRequest(servletRequest);//当前会话tokenattributes.put("authorization", token);//请求终端idattributes.put(SocketUtil.USER_ID, userTokenInfoVo.getUserId());//当前链接客户端类型attributes.put(SocketUtil.CLIENT_TYPE, StringUtils.isBlank(clientType)? "SYSTEM_ADMIN":clientType);//获取客户端ipString clientIp = IpUtils.getIpAddr(servletRequest);attributes.put(SocketUtil.CLIENT_IP, clientIp);log.error("开始握手完毕 {}", LocalDateTime.now());return true;}@Overridepublic void afterHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Exception exception) {log.error("afterHandshake {}", LocalDateTime.now());}
}
2 解决方案
原因分析:
找到服务器上的进程名
jps -l
使用jstack 进程号
查看自己服务堆栈的线程
3 解决方案
在系统hosts文件中增加本地ip地址与主机名的对应项
-
ifconfig 查看本机 ip
-
修改hosts文件 sudo vim /etc/hosts
-
在文件中追加 192.168.0.224 myserver --myserver 这个随便起名
-
测试 ping myserve