2017-09-25 3 views
0

vertime을 awakeResult와 같은 awaitEvent와 같은 함수와 함께 사용하려는 동기식 방식으로 Vertx를 사용하려고합니다. 나는 이렇게하기 위해 이것을 link 따라 갔다. 여기vertx : awaitResult 함수를 사용하여 오류가 발생했습니다.

라인은 내가 실행하려고한다 :

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

을하지만, 나는 folloing 오류가 :

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) 

나는이 문제를 해결 수있는 방법을 알고 있습니까?

답변

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

얻어진 콘솔 출력이다

<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> 

이 예이다

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

관련 종속성이 (받는다는 좌표로 표현) 꽤 자기 포함되어 있으므로 '있는 그대로'붙잡을 수 있어야합니다. 이 방법이 효과가 없다면 질문을 추가 세부 정보로 업데이트 할 수 있습니다. 이상적으로는 MCVE을 제공하지만 최소한 (자동) 동기화를 둘러싼 몇 줄 만이 아니라 모든 지형을 정의하는 코드를 보여줍니다. 호출)과 (b)이 verticle을 배치하는 코드.

+0

나를 위해 작동합니다. 그러나, 나는 루트 안에서 같은 일을하려고 노력하고있다. 아마도 이것은 이유이지만 나는 여전히 그것을 해결할 수 없었다! –

+0

질문을 업데이트하여 (a) 버티컬을 정의하는 코드 (동기화 호출 주변의 몇 줄뿐 아니라 모두)와 (b)이 버텍 클을 배치하는 코드를 표시 할 수 있습니다. – glytching