AsynchronousChannelGroup 在 shutdown 和 shutdownNow 无力!求解决啊

riasiao 2013-01-24 12:48:35
AsynchronousChannelGroup

shutdown 线程一直不关闭

shutdownNow 会抛出异常

java.nio.channels.AsynchronousCloseException
at sun.nio.ch.WindowsAsynchronousServerSocketChannelImpl$AcceptTask.failed(Unknown Source)
at sun.nio.ch.Iocp$EventHandlerTask.run(Unknown Source)
at sun.nio.ch.AsynchronousChannelGroupImpl$1.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)


使用:


this.channelGroup = AsynchronousChannelGroup.withFixedThreadPool(this.threadCount, Executors.defaultThreadFactory());
// this.channelGroup = AsynchronousChannelGroup.withFixedThreadPool(this.threadCount, Executors.privilegedThreadFactory());
// this.channelGroup = AsynchronousChannelGroup.withCachedThreadPool(Executors.newCachedThreadPool(), this.threadCount);
this.serverChannel = AsynchronousServerSocketChannel.open(this.channelGroup);
this.serverChannel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
this.serverChannel.bind(this.address);


if (this.serverChannel.isOpen()) {
Connection connection = new Connection();
this.serverChannel.accept(connection, new ConnectionAcceptHandler());
}


哪位大哥能帮忙...这怎么正常关闭啊?

...全文
244 3 打赏 收藏 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
赏金--猎人 2013-01-24
  • 打赏
  • 举报
回复
这是jdk1.7里面的吧,没用过,不大清楚! lz是在找showdown和showdownNow的区别吗,如果是要关闭线程,为什么不用return呢
riasiao 2013-01-24
  • 打赏
  • 举报
回复
确切说,应该是AsynchronousServerSocketChannel在close的时候抛出了这个异常...

62,620

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧