CompletableFuture join()导致主线程挂起

时间:2019-03-07 06:07:03

标签: java asynchronous hang completable-future

我有两个代码块似乎导致主服务器线程挂起,但是我真的不确定为什么挂起...

public static synchronized CompletableFuture<Void> saveAllToDatabase() {
    return CompletableFuture.runAsync(() -> {
        for (UUID u : timeMap.keySet()) {
            saveUUIDToDatabase(u).join(); //This is PlaytimeManager:217
        }
    });
}

public static synchronized CompletableFuture<Void> saveUUIDToDatabase(UUID uuid) {
    return CompletableFuture.runAsync(() -> {
        if (timeMap.get(uuid) == null) return;
        long l = getTime(uuid);
        long p = getPoints(uuid).join(); //This is PlaytimeManager:199
        Playtime.getData().save(uuid, l, p);
    });
}

public static CompletableFuture<Long> getPoints(UUID u) {
    Database d = Playtime.getData();
    return CompletableFuture.supplyAsync(() -> {
        if (d.isSaved(u)) return getCachedPoints(u) == 0 ? d.getPlayer(u).getPoints() : getCachedPoints(u);
        return getCachedPoints(u);
    });
}

#join()方法导致了挂起,但是它们被包裹在异步CompletableFuture中,所以我不确定它的挂起是如何...

堆栈跟踪: https://pastebin.com/5QhJPPhn

0 个答案:

没有答案