2016-03-31 16 views

回答

4

根本就

public static void main(String[] args) { 
    Vertx vertx = Vertx.vertx(); 
    vertx.deployVerticle(MyVerticle.class.getName()); 
} 

public static void main(String[] args) { 
    Vertx vertx = Vertx.vertx(); 
    vertx.deployVerticle(new MyVerticle()); 
} 

编辑:正如威尔所说,这里是取结果纳入考虑,并阻止主线程,直到成功的例子:

BlockingQueue<AsyncResult<String>> q = new ArrayBlockingQueue<>(1); 
Vertx.vertx().deployVerticle(new Application(), q::offer); 
AsyncResult<String> result = q.take(); 
if (result.failed()) { 
    throw new RuntimeException(result.cause()); 
} 
+0

总是值得使用带结果的处理程序的重载方法。否则,您不会知道您的Verticle是否无法启动。 – Will

+0

@Will:谢谢,添加了一个考虑到这一点的例子。 –

+0

@AlexanderTorstling你可以更清楚地了解'result.cause()'?我看不到它来自哪里。 – thisdotvoid