vert.x 获取 - 无法创建子事件循环 [英] vert.x getting - failed to create a child event loop

查看:22
本文介绍了vert.x 获取 - 无法创建子事件循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建大约 150 个大约 5MB 大小的文件.Vertx 文件 API 在创建 10-15 个文件无法创建子事件循环"后随机给出异常.

I am creating about 150 files of around 5MB sizes. Vertx file APIs gives an exception randomly after creating 10-15 files "failed to create a child event loop".

(我使用的是 vertx3 和 java8)

(I am using vertx3 and java8)

以下是我的代码片段(在我收到回调后,我只会再次调用该函数来创建下一个文件.因此,文件创建永远不会并发):

Below is my code snippet (After I get a callback then only I call the function again to create the next file. So, file creation is never concurrent):

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();
});

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

Below is my exception stack trace:

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

推荐答案

我从论坛中得到了答案 这里(感谢 Jez)

I got my answer from the forum here (Thanks Jez)

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

Vertx.vertx() is the culprit. It creates a new vertx every time leading to multiple eventloops which seems to be the problem.

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

I cached it in a variable, rather than using Vertx.vertx() every time and it worked

cachedVertx.fileSystem().writeFile(...)

这篇关于vert.x 获取 - 无法创建子事件循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆