ExecutionHandler problem

Trustin Lee trustin at gleamynode.net
Tue Dec 30 01:48:48 EST 2008


Hi Marian,

You need to shut down the OrderedMemoryAwareThreadPoolExecutor that
you've created by yourself.  ChannelFactory.releaseExternalResources()
will not shut down the Executor that is used by ExecutionHandler.
Please call OrderedMemoryAwareThreadPoolExecutor.shutdown() after
calling ChannelFactory.releaseExternalResources(), then everything
should be cleaned up.

HTH,
Trustin

On Tue, Dec 30, 2008 at 2:09 AM, Marian Stranecky
<marian.stranecky at mobilbonus.cz> wrote:
> Hi all,
>
> I would like to ask you for information of how to connect and shutdown the
> client properly, because I have experienced a problem with netty while
> trying to use an ExecutionHandler:
> The threads created in OrderedMemoryAwareThreadPoolExecutor and used in
> handling are running even after the channel is closed (e.g. closed by a
> server after the channel is marked idle)
>
> Thanks in advance,
>
> Marian
>
> public ChannelPipeline getPipeline() throws Exception {
>
> ChannelPipeline pipeline = pipeline();
>
> // Add the number codec first,
> pipeline.addLast("decoder", new MyMessageDecoder());
> pipeline.addLast("encoder", new MyMessageEncoder());
>
> // utilize the processing
> // pipeline.addLast("executor", new ExecutionHandler(new
> OrderedMemoryAwareThreadPoolExecutor(16, 1048576, 1048576)));
>
>
> // and then business logic.
> pipeline.addLast("handler", new OISDClientHandler(this.client));
>
> return pipeline;
> }
>
>
> The client is as follows:
>
> public void connect(){
> ExecutorService bossExecutor = Executors.newCachedThreadPool(new
> CustomThreadFactory("bossExecutorPool"));
> ExecutorService workerExecutor = Executors.newCachedThreadPool(new
> CustomThreadFactory("workerExecutorPool"));
>
> ChannelFactory factory = new NioClientSocketChannelFactory(bossExecutor,
> workerExecutor);
>
> ClientBootstrap bootstrap = new ClientBootstrap(factory);
>
> bootstrap.setPipelineFactory(new OISDClientPipelineFactory(this));
>
> HashMap<String, Object> opts = new HashMap<String, Object>();
>
> opts.put("tcpNoDelay", false);
> opts.put("keepAlive", true);
>
> bootstrap.setOptions(opts);
>
> ChannelFuture connectFuture = bootstrap.connect(this.SMSCAddress);
>
> // Wait until the connection attempt succeeds or fails.
> this.channel = connectFuture.awaitUninterruptibly().getChannel();
>
> if (!connectFuture.isSuccess()) {
> log.error("Problem while connecting to " + this.SMSCAddress.toString(),
> connectFuture.getCause());
> return;
> }
>
> // Wait for the server to close the connection.
> channel.getCloseFuture().awaitUninterruptibly();
>
> // Shut down executor threads to exit.
> factory.releaseExternalResources();
> log.debug("resources released...");
> }
>
>
> _______________________________________________
> netty-users mailing list
> netty-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/netty-users
>
>



-- 
Trustin Lee, Principal Software Engineer, JBoss, a division of Red Hat
--
what we call human nature in actuality is human habit
--
http://gleamynode.net/



More information about the netty-users mailing list