如何使用while()循环在vertx上运行无限循环 [英] How to run infinite loop on vertx using while() loop
本文介绍了如何使用while()循环在vertx上运行无限循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在diff线程的verx上运行无限循环. 应该是这样的:
I would like to run an infinite loop on verx on diff thread. Should be something like this:
vertx.executeBlocking(future -> {
while(true){
}
//some logic (e.g waiting on blocking-code)
}
问题是,即使对于executeBlocking线程,在vertx上您也可以增加全局超时.但我想为此执行设置非超时警告,因为它将永远运行
thing is that on vertx even for executeBlocking threads you have global timeout which you can increase. but I would like to set for this execution non-timeout warnings as it will run forever
- 我可以通过vertx实现我的目标吗?
- 如果情况为1,则为true.如何从超时警告中排除此特定的阻止执行
推荐答案
我有一个类似的用例,当我需要使用一个阻塞的api时,我使用了以下代码
I have a similar use case, when I need to consume a blocking api, I have used the following code
@Override
public void start() {
vertx.<Void>executeBlocking(f -> {
while (true) {
// blocking...
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
vertx.eventBus().publish("channel.1", "msg");
}
}, voidAsyncResult -> System.out.println("done"));
}
这篇关于如何使用while()循环在vertx上运行无限循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文