首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >vert.x loop创建子事件循环失败

vert.x loop创建子事件循环失败
EN

Stack Overflow用户
提问于 2015-12-15 15:49:30
回答 1查看 1.9K关注 0票数 3

我正在创建大约150个文件,大约5MB的大小。Vertx文件API在创建10-15个文件“创建子事件循环失败”后随机提供异常。

(我正在使用vertx3和java8)

下面是我的代码片段(在我得到回调之后,只有我再次调用函数来创建下一个文件。因此,文件创建从来都不是并发的):

代码语言:javascript
复制
Vertx.vertx().fileSystem().writeFile(filepath,
       Buffer.buffer(dataList.toString()), result -> {
 if (result.succeeded()) {
   System.out.println("File written");
 } else {
  System.err.println("Oh oh ..." + result.cause());
 }
 lambda.callback();
});

下面是我的异常堆栈跟踪:

代码语言:javascript
复制
java.lang.IllegalStateException: failed to create a child event loop
    at io.netty.util.concurrent.MultithreadEventExecutorGroup.<init>(MultithreadEventExecutorGroup.java:68)
    at io.netty.channel.MultithreadEventLoopGroup.<init>(MultithreadEventLoopGroup.java:49)
    at io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:61)
    at io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:52)
    at io.vertx.core.impl.VertxImpl.<init>(VertxImpl.java:132)
    at io.vertx.core.impl.VertxImpl.<init>(VertxImpl.java:126)
    at io.vertx.core.impl.VertxImpl.<init>(VertxImpl.java:122)
    at io.vertx.core.impl.VertxFactoryImpl.vertx(VertxFactoryImpl.java:34)
    at io.vertx.core.Vertx.vertx(Vertx.java:78)
    at rc_datawarehouse.CsvToJsonChunkWriter.writeCsvChunkToFiles(CsvToJsonChunkWriter.java:73)
    at rc_datawarehouse.CsvToJsonReadWrite.lambda$2(CsvToJsonReadWrite.java:119)
    at rc_datawarehouse.CsvToJsonReadWrite$$Lambda$16/1470881859.handle(Unknown Source)
    at io.vertx.core.file.impl.AsyncFileImpl.handleData(AsyncFileImpl.java:335)
    at io.vertx.core.file.impl.AsyncFileImpl.lambda$doRead$285(AsyncFileImpl.java:320)
    at io.vertx.core.file.impl.AsyncFileImpl$$Lambda$17/1067800899.handle(Unknown Source)
    at io.vertx.core.file.impl.AsyncFileImpl$2.lambda$done$289(AsyncFileImpl.java:408)
    at io.vertx.core.file.impl.AsyncFileImpl$2$$Lambda$18/1632681662.handle(Unknown Source)
    at io.vertx.core.impl.ContextImpl.lambda$wrapTask$15(ContextImpl.java:314)
    at io.vertx.core.impl.ContextImpl$$Lambda$5/1780132728.run(Unknown Source)
    at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:357)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:357)
    at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:111)
    at java.lang.Thread.run(Unknown Source)
Caused by: io.netty.channel.ChannelException: failed to open a new selector
    at io.netty.channel.nio.NioEventLoop.openSelector(NioEventLoop.java:128)
    at io.netty.channel.nio.NioEventLoop.<init>(NioEventLoop.java:120)
    at io.netty.channel.nio.NioEventLoopGroup.newChild(NioEventLoopGroup.java:87)
    at io.netty.util.concurrent.MultithreadEventExecutorGroup.<init>(MultithreadEventExecutorGroup.java:64)
    ... 22 more
Caused by: java.io.IOException: Unable to establish loopback connection
    at sun.nio.ch.PipeImpl$Initializer.run(Unknown Source)
    at sun.nio.ch.PipeImpl$Initializer.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.nio.ch.PipeImpl.<init>(Unknown Source)
    at sun.nio.ch.SelectorProviderImpl.openPipe(Unknown Source)
    at java.nio.channels.Pipe.open(Unknown Source)
    at sun.nio.ch.WindowsSelectorImpl.<init>(Unknown Source)
    at sun.nio.ch.WindowsSelectorProvider.openSelector(Unknown Source)
    at io.netty.channel.nio.NioEventLoop.openSelector(NioEventLoop.java:126)
    ... 25 more
Caused by: java.net.SocketException: No buffer space available (maximum connections reached?): connect
    at sun.nio.ch.Net.connect0(Native Method)
    at sun.nio.ch.Net.connect(Unknown Source)
    at sun.nio.ch.Net.connect(Unknown Source)
    at sun.nio.ch.SocketChannelImpl.connect(Unknown Source)
    at java.nio.channels.SocketChannel.open(Unknown Source)
    at sun.nio.ch.PipeImpl$Initializer$LoopbackConnector.run(Unknown Source)
    ... 34 more
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-12-15 17:24:38

我从论坛这里收到了我的答案(谢谢Jez)

Vertx.vertx()是罪魁祸首它每次都会创建一个新的vertx,从而导致多个事件循环,这似乎就是问题所在。

我把它缓存在一个变量中,而不是每次都使用Vertx.vertx(),而且它工作了。

代码语言:javascript
复制
cachedVertx.fileSystem().writeFile(...)
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34293532

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档