怎样解决死锁的问题
老师有没有讲解死锁的教程啊,请教学
老师有没有讲解死锁的教程啊,请教学
2015-08-22
final NioSocketConnector connector = getConnector();
connector.getFilterChain().addLast("transportCoder",
new ProtocolCodecFilter(new CustomProtocolCodecFactory(Charset.forName("UTF-8"))));
connector.getSessionConfig().setReceiveBufferSize(2048);//接收缓冲区1M
connector.setConnectTimeoutMillis(ConfigBean.getHeartbeatTimeout()); // 设置连接超时
connector.setHandler(new TcpClientHandler());// 设置消息处理器
connector.getFilterChain().addLast("exceutor", new ExecutorFilter());
//=============添加监控,断线重连============
connector.setDefaultRemoteAddress(new InetSocketAddress(ConfigBean.getOpenRestyUrl(),ConfigBean.getOpenRestyPort()));
connector.addListener(new IoListener(){
@Override
public void sessionDestroyed(IoSession arg)throws Exception{
cfs=null;
for (;;) {
if (isHostConnectable(ConfigBean.getOpenRestyUrl(), ConfigBean.getOpenRestyPort())) {
try {
Thread.sleep(5000);
ConnectFuture future = connector.connect();
future.awaitUninterruptibly();// 等待连接创建完成 这里可能出现死锁
session = future.getSession();
if (session.isConnected()) {
cfs=future;
logger.info("断线重连[" + connector.getDefaultRemoteAddress().getHostName() + ":" + connector.getDefaultRemoteAddress().getPort() + "]成功");
break;
}
} catch (Exception e) {
cfs=null;
logger.error("重连服务器登录失败,5秒再连接一次:" + e.getMessage());
}
}
}
}
});
举报