Fix storage not saving when exiting while saving

This commit is contained in:
crschnick 2024-05-07 10:51:12 +00:00
parent 9d4c4fe97d
commit 9e95c6b5b4

View file

@ -17,6 +17,7 @@ import java.util.ArrayList;
import java.util.Base64; import java.util.Base64;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -226,7 +227,18 @@ public class StandardStorage extends DataStorage {
} }
public void save(boolean dispose) { public void save(boolean dispose) {
if (!busyIo.tryLock()) { try {
// If another save operation is in progress, we have to wait on dispose
// Otherwise the application may quit and kill the daemon thread that is performing the other save operation
if (dispose && !busyIo.tryLock(1, TimeUnit.MINUTES)) {
return;
}
} catch (InterruptedException e) {
return;
}
// We don't need to wait on normal saves though
if (!dispose && !busyIo.tryLock()) {
return; return;
} }