mirror of
https://github.com/qaiu/netdisk-fast-download.git
synced 2026-06-10 23:47:29 +00:00
fix(web-service): DbServiceImpl Thread.sleep 改为 vertx.setTimer 避免阻塞 event loop
sayOk() 中使用 Thread.sleep(4000) 会阻塞 Vert.x event loop 线程, 改为 vertx.setTimer 异步延迟完成 promise。
This commit is contained in:
@@ -42,12 +42,11 @@ public class DbServiceImpl implements DbService {
|
||||
@Override
|
||||
public Future<JsonObject> sayOk(String data) {
|
||||
log.info("say ok1 -> wait...");
|
||||
try {
|
||||
Thread.sleep(4000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return Future.succeededFuture(JsonObject.mapFrom(JsonResult.data("Hi: " + data)));
|
||||
Promise<JsonObject> promise = Promise.promise();
|
||||
cn.qaiu.vx.core.util.VertxHolder.getVertxInstance().setTimer(4000, id -> {
|
||||
promise.complete(JsonObject.mapFrom(JsonResult.data("Hi: " + data)));
|
||||
});
|
||||
return promise.future();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user