2016-04-03 51 views
2

我使用的IntelliJ來調試運行Vert.X 3應用程序和時間將近50%,當我按下重新啓動按鈕我得到這個錯誤:的IntelliJ Vertx調試重啓競爭條件

我按下這個按鈕重建/重新啓動應用程序:

restart image button

Apr 02, 2016 7:17:03 PM io.vertx.core.http.impl.HttpServerImpl SEVERE: java.net.BindException: Address already in use

這意味着調試器並沒有殺死端口,並再次啓動它,它已經準備好了。這是非常可變的。

我的gradle調試相當簡單,我已經檢查了單實例只有選項。

intellij gradle debug configuration

有誰知道如何重新調試運行,而不會導致這種競爭情況?

回答

3

您是否正確關閉了您的HTTPServer & Verticle並在完成所有工作時發送信號給Vertx?

我有這個完全相同的問題(儘管在測試中),但通過正確關閉我的服務器和Verticle來解決它。

下面是一些示例代碼(使用Rx版)

@Override 
    public void stop(Future<Void> stopFuture) { 

     httpServer.closeObservable() 
       .subscribe(
         aVoid -> { 
         }, 
         error -> { 
          logger.error("Could not shutdown HTTP Server ", error); 
          stopFuture.fail(error); 
         }, 
         () -> { 
          logger.info("HTTP Server Shutdown"); 
          stopFuture.complete(); 
         }); 
    } 
+0

謝謝你的代碼...但如何將這項工作,如果我從一個main函數運行呢? –

+2

它沒有任何區別。如果你用'vertx.deployVerticle'&'vertx.undeploy'來啓動和停止'verticle',那麼'undeploy'會在你的Verticle中執行stop函數,這應該乾淨地關閉你的http服務器。 – Will

3

你verticle必須使用Future版本覆蓋停止功能。

喜歡的東西:

public void stop(Future<Void> future) { 
    httpServer.close(ar -> { 
     if (ar.succeeeded()) { future.complete(); } 
     else { 
     future.fail(ar.cause()); 
     } 
    }); 
}