Commit e1d56c3f authored by zengtianlai3's avatar zengtianlai3

2.3.9 异常处理:finally代码块中抛出异常

parent 62b1e32c
......@@ -27,29 +27,26 @@ public class TcpServer {
EventLoopGroup bossGroup = new NioEventLoopGroup(4);
EventLoopGroup workerGroup = new NioEventLoopGroup(4);
log.debug("Tcp服务,开始监听端口:{}",port);
//创建服务端的启动对象,设置参数
ServerBootstrap b = new ServerBootstrap();
//设置两个线程组boosGroup和workerGroup
b.group(bossGroup, workerGroup)
//设置服务端通道实现类型
.channel(NioServerSocketChannel.class)
// .handler(new LoggingHandler(LogLevel.INFO))
.childHandler(channelInitializer)
// 设置tcp缓冲区
.option(ChannelOption.SO_BACKLOG, 1024)
//设置保持活动连接状态
.childOption(ChannelOption.SO_KEEPALIVE, true);
ChannelFuture f;
try {
//创建服务端的启动对象,设置参数
ServerBootstrap b = new ServerBootstrap();
//设置两个线程组boosGroup和workerGroup
b.group(bossGroup, workerGroup)
//设置服务端通道实现类型
.channel(NioServerSocketChannel.class)
// .handler(new LoggingHandler(LogLevel.INFO))
.childHandler(channelInitializer)
// 设置tcp缓冲区
.option(ChannelOption.SO_BACKLOG, 1024)
//设置保持活动连接状态
.childOption(ChannelOption.SO_KEEPALIVE, true);
ChannelFuture f;
try {
f = b.bind(port).sync();
f.channel().closeFuture().sync();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
log.error("Tcp服务异常,端口:{}",port);
}
} finally {
f = b.bind(port).sync();
f.channel().closeFuture().sync();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
log.error("Tcp服务异常,端口:{}",port);
}finally {
log.debug("Tcp服务,停止退出");
workerGroup.shutdownGracefully();
bossGroup.shutdownGracefully();
......
......@@ -22,7 +22,7 @@ public class ResourceManager {
@Autowired
ResourceService resourceService;
public void downloadDeviceInfoExcle(HttpServletResponse response, int userId){
public void downloadDeviceInfoExcle(HttpServletResponse response, int userId) throws IOException {
OutputStream os = null;
HSSFWorkbook wb = null;
try {
......@@ -115,15 +115,11 @@ public class ResourceManager {
} catch (IOException e) {
log.error("Excel表格信息下载异常,{}",e.getMessage());
} finally {
try {
if (os != null) {
os.close();
}
if (wb != null) {
wb.close();
}
} catch (IOException e) {
log.error("Excel表格信息下载异常,{}",e.getMessage());
if (os != null) {
os.close();
}
if (wb != null) {
wb.close();
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment