Netty lags for a few seconds before shutting down -
iv been doing network programming while , converted 1 of projects netty. iv been bothered lot fact unlike original program, client freeze 3-5 seconds before closing, enough make me end force terminating everytime because don't want wait it. normal netty? doing wrong?
main method:
public static void main(string[] args) throws exception { final sslcontext sslctx = sslcontext.newclientcontext(insecuretrustmanagerfactory.instance); eventloopgroup group = new nioeventloopgroup(); try { bootstrap b = new bootstrap(); b.group(group) .channel(niosocketchannel.class) .handler(new networkinitializer(sslctx)); // start connection attempt. ch = b.connect(host, port).sync().channel(); //sends clients name server askname(); //loop simple gl stuff , gameplay updating, posted below while(running){loop(); if (display.iscloserequested()){ running = false; if (lastwritefuture != null) { lastwritefuture.sync(); } //tells server shut down write("9"); ch.closefuture().sync(); group.shutdowngracefully(); system.out.println("herro der"); break; } } } { group.shutdowngracefully(); // connection closed automatically on shutdown. } }
loop class:
private static void loop() { gl11.glclear(gl11.gl_color_buffer_bit); //main update method game. calculations , stuff. can post if neccisary kinda big. spacestate.update(); display.update(); display.sync(60); }
group.shutdowngracefully();
default waits 3 seconds until pending tasks executed before terminates itself. can specify different timeout value, small value has risk of getting rejectedexecutionexception
. if sure application has no business left event loop group, can specify small value terminate immediately.
Comments
Post a Comment