<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"><html><head><meta name="qrichtext" content="1" /><style type="text/css">p, li { white-space: pre-wrap; }</style></head><body style=" font-family:'Sans Serif'; font-size:10pt; font-weight:400; font-style:normal;">Thanks for your answer, Trustin.<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>I was just wondering if there is a more generic way to handle this. IMHO when there is an institute of ExecutionHandler we should be able to shutdown it transparently (e.g. by signaling somewhere in the pipeline).<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>Anyway, as far as I see, it should be handled now by this piece of code in "client" (to avoid pushing a referable instance of an Executor to the PipelineFactory):<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>                ExecutionHandler execHandler = (ExecutionHandler) channel.getPipeline().get("executor");<br>
                ExecutorService es = (ExecutorService) execHandler.getExecutor();<br>
                es.shutdown();<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>Am I right?<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>TIA,<br>
Marian<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p><p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>On Tuesday 30 of December 2008 07:48:48 Trustin Lee wrote:<br>
&gt; Hi Marian,<br>
&gt;<br>
&gt; You need to shut down the OrderedMemoryAwareThreadPoolExecutor that<br>
&gt; you've created by yourself.  ChannelFactory.releaseExternalResources()<br>
&gt; will not shut down the Executor that is used by ExecutionHandler.<br>
&gt; Please call OrderedMemoryAwareThreadPoolExecutor.shutdown() after<br>
&gt; calling ChannelFactory.releaseExternalResources(), then everything<br>
&gt; should be cleaned up.<br>
&gt;<br>
&gt; HTH,<br>
&gt; Trustin<br>
&gt;<br>
&gt; On Tue, Dec 30, 2008 at 2:09 AM, Marian Stranecky<br>
&gt;<br>
&gt; &lt;marian.stranecky@mobilbonus.cz&gt; wrote:<br>
&gt; &gt; Hi all,<br>
&gt; &gt;<br>
&gt; &gt; I would like to ask you for information of how to connect and shutdown<br>
&gt; &gt; the client properly, because I have experienced a problem with netty<br>
&gt; &gt; while trying to use an ExecutionHandler:<br>
&gt; &gt; The threads created in OrderedMemoryAwareThreadPoolExecutor and used in<br>
&gt; &gt; handling are running even after the channel is closed (e.g. closed by a<br>
&gt; &gt; server after the channel is marked idle)<br>
&gt; &gt;<br>
&gt; &gt; Thanks in advance,<br>
&gt; &gt;<br>
&gt; &gt; Marian<br>
&gt; &gt;<br>
&gt; &gt; public ChannelPipeline getPipeline() throws Exception {<br>
&gt; &gt;<br>
&gt; &gt; ChannelPipeline pipeline = pipeline();<br>
&gt; &gt;<br>
&gt; &gt; // Add the number codec first,<br>
&gt; &gt; pipeline.addLast("decoder", new MyMessageDecoder());<br>
&gt; &gt; pipeline.addLast("encoder", new MyMessageEncoder());<br>
&gt; &gt;<br>
&gt; &gt; // utilize the processing<br>
&gt; &gt; // pipeline.addLast("executor", new ExecutionHandler(new<br>
&gt; &gt; OrderedMemoryAwareThreadPoolExecutor(16, 1048576, 1048576)));<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt; // and then business logic.<br>
&gt; &gt; pipeline.addLast("handler", new OISDClientHandler(this.client));<br>
&gt; &gt;<br>
&gt; &gt; return pipeline;<br>
&gt; &gt; }<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt; The client is as follows:<br>
&gt; &gt;<br>
&gt; &gt; public void connect(){<br>
&gt; &gt; ExecutorService bossExecutor = Executors.newCachedThreadPool(new<br>
&gt; &gt; CustomThreadFactory("bossExecutorPool"));<br>
&gt; &gt; ExecutorService workerExecutor = Executors.newCachedThreadPool(new<br>
&gt; &gt; CustomThreadFactory("workerExecutorPool"));<br>
&gt; &gt;<br>
&gt; &gt; ChannelFactory factory = new NioClientSocketChannelFactory(bossExecutor,<br>
&gt; &gt; workerExecutor);<br>
&gt; &gt;<br>
&gt; &gt; ClientBootstrap bootstrap = new ClientBootstrap(factory);<br>
&gt; &gt;<br>
&gt; &gt; bootstrap.setPipelineFactory(new OISDClientPipelineFactory(this));<br>
&gt; &gt;<br>
&gt; &gt; HashMap&lt;String, Object&gt; opts = new HashMap&lt;String, Object&gt;();<br>
&gt; &gt;<br>
&gt; &gt; opts.put("tcpNoDelay", false);<br>
&gt; &gt; opts.put("keepAlive", true);<br>
&gt; &gt;<br>
&gt; &gt; bootstrap.setOptions(opts);<br>
&gt; &gt;<br>
&gt; &gt; ChannelFuture connectFuture = bootstrap.connect(this.SMSCAddress);<br>
&gt; &gt;<br>
&gt; &gt; // Wait until the connection attempt succeeds or fails.<br>
&gt; &gt; this.channel = connectFuture.awaitUninterruptibly().getChannel();<br>
&gt; &gt;<br>
&gt; &gt; if (!connectFuture.isSuccess()) {<br>
&gt; &gt; log.error("Problem while connecting to " + this.SMSCAddress.toString(),<br>
&gt; &gt; connectFuture.getCause());<br>
&gt; &gt; return;<br>
&gt; &gt; }<br>
&gt; &gt;<br>
&gt; &gt; // Wait for the server to close the connection.<br>
&gt; &gt; channel.getCloseFuture().awaitUninterruptibly();<br>
&gt; &gt;<br>
&gt; &gt; // Shut down executor threads to exit.<br>
&gt; &gt; factory.releaseExternalResources();<br>
&gt; &gt; log.debug("resources released...");<br>
&gt; &gt; }<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt; _______________________________________________<br>
&gt; &gt; netty-users mailing list<br>
&gt; &gt; netty-users@lists.jboss.org<br>
&gt; &gt; https://lists.jboss.org/mailman/listinfo/netty-users<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p></body></html>