shut down acquires trade lock until no delay so other threads can finish

This commit is contained in:
woodser 2023-04-25 19:04:43 -04:00
parent 5545bcde38
commit 4cf6992113

View File

@ -1148,9 +1148,15 @@ public abstract class Trade implements Tradable, Model {
public void onShutDownStarted() {
isShutDownStarted = true;
if (wallet != null) log.info("{} {} preparing for shut down", getClass().getSimpleName(), getId());
synchronized (this) {
synchronized (walletLock) {
stopPolling(); // allow locks to release before stopping
// allow other threads to finish processing by acquiring trade locks until there's no delay
int maxAttempts = 10;
for (int i = 0; i < maxAttempts; i++) {
long startTimeMs = System.currentTimeMillis();
synchronized (this) {
synchronized (walletLock) {
if (System.currentTimeMillis() - startTimeMs <= 10 || isShutDown) break;
}
}
}
}