我有两个代码块似乎导致主服务器线程挂起,但是我真的不确定为什么挂起...
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
中,所以我不确定它的挂起是如何...