mirror of
https://github.com/boldsuck/haveno.git
synced 2025-01-10 01:54:31 +00:00
shut down acquires trade lock until no delay so other threads can finish
This commit is contained in:
parent
5545bcde38
commit
4cf6992113
1 changed files with 9 additions and 3 deletions
|
@ -1148,9 +1148,15 @@ public abstract class Trade implements Tradable, Model {
|
||||||
public void onShutDownStarted() {
|
public void onShutDownStarted() {
|
||||||
isShutDownStarted = true;
|
isShutDownStarted = true;
|
||||||
if (wallet != null) log.info("{} {} preparing for shut down", getClass().getSimpleName(), getId());
|
if (wallet != null) log.info("{} {} preparing for shut down", getClass().getSimpleName(), getId());
|
||||||
|
|
||||||
|
// 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 (this) {
|
||||||
synchronized (walletLock) {
|
synchronized (walletLock) {
|
||||||
stopPolling(); // allow locks to release before stopping
|
if (System.currentTimeMillis() - startTimeMs <= 10 || isShutDown) break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue