Thank you very much Hack,
You are right, It was the case that I didn't invoke ctx.close().
Then based on the same code, I commented out ctx.close() and tried to close channel out side of channel handler, with following lines.
ChannelFuture f = b.connect(new RxtxDeviceAddress("COM11")).sync();
Thread.sleep(3000);
f.channel().close();
Then will get an exception:
java.lang.NullPointerException
at io.netty.channel.oio.OioByteStreamChannel.available(OioByteStreamChannel.java:77)
at io.netty.channel.oio.OioByteStreamChannel.doReadBytes(OioByteStreamChannel.java:85)
at io.netty.channel.oio.AbstractOioByteChannel.doRead(AbstractOioByteChannel.java:85)
at io.netty.channel.oio.AbstractOioChannel$1.run(AbstractOioChannel.java:40)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:324)
at io.netty.channel.ThreadPerChannelEventLoop.run(ThreadPerChannelEventLoop.java:69)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:101)
at java.lang.Thread.run(Unknown Source)
Did I missed anything in this case?
Thanks a lot!
-Shawn