fix resources leak

This commit is contained in:
MaximZaitsev
2016-07-28 12:32:23 +03:00
parent 6bc5874eb5
commit 2da1a3de9a
+6 -2
View File
@@ -123,9 +123,10 @@ fun getCarServerThread(): Thread {
val bossGroup = NioEventLoopGroup(1)
val workerGroup = NioEventLoopGroup()
val b = ServerBootstrap()
val initializer = car.server.Initializer(handlerThreadsCount)
b.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel().javaClass)
.childHandler(car.server.Initializer(handlerThreadsCount))
.childHandler(initializer)
try {
val channel = b.bind(carServerPort).sync().channel()
@@ -135,6 +136,7 @@ fun getCarServerThread(): Thread {
} finally {
bossGroup.shutdownGracefully()
workerGroup.shutdownGracefully()
initializer.group.shutdownGracefully()
}
})
}
@@ -145,9 +147,10 @@ fun getWebServerThread(): Thread {
val bossGroup = NioEventLoopGroup(1)
val workerGroup = NioEventLoopGroup()
val b = ServerBootstrap()
val initializer = web.server.Initializer(handlerThreadsCount)
b.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel().javaClass)
.childHandler(web.server.Initializer(handlerThreadsCount))
.childHandler(initializer)
try {
val channel = b.bind(webServerPort).sync().channel()
@@ -157,6 +160,7 @@ fun getWebServerThread(): Thread {
} finally {
bossGroup.shutdownGracefully()
workerGroup.shutdownGracefully()
initializer.group.shutdownGracefully()
}
})
}