import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import java.net.InetSocketAddress;
public class NettySequencingServer {
private final int port;
public NettySequencingServer(int port) {
this.port = port;
}
public static void main(String[] args) throws Exception {
int port = 5000;
NettySequencingServer nettySequencingServer = new NettySequencingServer(port);
for (int i = 0; i < 10000; i++) {
nettySequencingServer.startStop();
}
}
public void startStop() throws Exception {
final Decoder decoder = new Decoder();
EventLoopGroup group = new NioEventLoopGroup(1);
ServerBootstrap b = new ServerBootstrap();
b.group(group)
.channel(NioServerSocketChannel.class)
.localAddress(new InetSocketAddress(port))
.childHandler(new ChannelInitializer<SocketChannel>(){
@Override
public void initChannel(SocketChannel ch) {
ch.pipeline().addLast(decoder);
}
});
try {
ChannelFuture startFuture = b.bind();
Channel channel = startFuture.channel();
// Start Server
startFuture.sync();
if (!startFuture.isSuccess()) {
System.out.println("Start failed");
}
// Stop Server
ChannelFuture stopFuture = channel.disconnect().sync();
if (!stopFuture.isSuccess()) {
System.out.println("Stop failed");
}
} catch (Exception e) {
System.out.println(e.getMessage());
for (StackTraceElement ele : e.getStackTrace()) {
System.out.println(ele.toString());
}
}
}
}
Hi,
if I remember correctly you also have to free the EventLoopGroup to release all ressources completely.
Could you try that?
Best
Julian
--
You received this message because you are subscribed to the Google Groups "Netty discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
netty+un...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/netty/CAJt14FNODZsszdGWcKUz%2BmGc6izcTdFFVQy2HQNDrPJRjnaj3g%40mail.gmail.com.