【问题标题】:vertx: error by using awaitResult functionvertx:使用 awaitResult 函数出错
【发布时间】:2017-09-26 07:14:52
【问题描述】:

我正在尝试以同步方式使用 Vertx,这也是我尝试使用 vert-sync 和 awaitEvent、awatResult 等功能的原因。 我按照这个link 来做到这一点。

这是我要运行的行:

long tid = awaitEvent(h -> vertx.setTimer(1000, h));
System.out.println("Timer has now fired");

但是,我收到以下错误:

sept. 25, 2017 11:25:41 PM io.vertx.ext.web.impl.RoutingContextImplBase
GRAVE: Unexpected exception in route
java.lang.StackOverflowError
    at io.vertx.ext.web.impl.RoutingContextWrapper.request(RoutingContextWrapper.java:57)
    at io.vertx.ext.web.impl.RoutingContextWrapper.request(RoutingContextWrapper.java:57)
    at io.vertx.ext.web.impl.RoutingContextWrapper.request(RoutingContextWrapper.java:57)
    at io.vertx.ext.web.impl.RoutingContextWrapper.request(RoutingContextWrapper.java:57)
    at io.vertx.ext.web.impl.RoutingContextWrapper.request(RoutingContextWrapper.java:57)
    at io.vertx.ext.web.impl.RoutingContextWrapper.request(RoutingContextWrapper.java:57)

你知道我该如何解决这个问题吗?

【问题讨论】:

    标签: vert.x


    【解决方案1】:

    这个简单的例子有效:

    import co.paralleluniverse.fibers.Suspendable;
    import io.vertx.core.Vertx;
    import io.vertx.ext.sync.Sync;
    import io.vertx.ext.sync.SyncVerticle;
    
    public class SyncExample extends SyncVerticle {
    
        public static void main(String[] args) {
            Vertx vertx = Vertx.vertx();
    
            vertx.deployVerticle(SyncExample.class.getName());
        }
    
        @Suspendable
        @Override
        public void start() throws Exception {
            System.out.println("Waiting for single event");
            long tid = Sync.awaitEvent(h -> vertx.setTimer(1000, h));
            System.out.println("Single event has fired with timerId=" + tid);
        }
    }
    

    得到的控制台输出是:

    Waiting for single event
    Waiting for single event
    Single event has fired with timerId=0
    

    相关的依赖(以maven坐标表示)为:

    <dependency>
        <groupId>io.vertx</groupId>
        <artifactId>vertx-sync</artifactId>
        <version>3.4.1</version>
    </dependency>
    <dependency>
        <groupId>co.paralleluniverse</groupId>
        <artifactId>quasar-core</artifactId>
        <version>0.7.9</version>
    </dependency>
    

    这个例子是完全独立的,所以你应该能够“按原样”抓住它。如果这对您不起作用,那么也许您可以使用其他详细信息更新您的问题,理想情况下提供MCVE 但至少向我们展示(a)定义您的verticle的代码(所有这些不仅仅是周围的几行同步调用)和(b)部署这个verticle的代码。

    【讨论】:

    • 它对我有用。但是,我正在尝试在一条路线中做同样的事情,也许这就是原因,但我仍然无法解决它!
    • 您也许可以更新您的问题以向我们展示 (a) 定义您的 verticle 的代码(所有这些代码不仅仅是同步调用周围的几行)和 (b) 部署此 verticle 的代码.
    猜你喜欢
    • 1970-01-01
    • 2022-01-08
    • 1970-01-01
    • 2017-09-05
    • 1970-01-01
    • 2017-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多