mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-11 23:00:59 +00:00
fixed synchornization problem that in some cases lead to race definition lookups not getting unblocked properly
Change-Id: Icd0cfd3bdfb8c37a8df1997814da4aabe38c6859
This commit is contained in:
1 parent
2c42cd0653
commit
cd67b2ea2f
1 file changed
+16
-12
+16
-12
@@ -318,21 +318,25 @@ public class DomainFactoryImpl implements DomainFactory {
|
||||
long start = System.currentTimeMillis();
|
||||
RaceDefinition result = raceCache.get(raceId);
|
||||
boolean interrupted = false;
|
||||
while ((timeoutInMilliseconds == -1 || System.currentTimeMillis()-start < timeoutInMilliseconds) && !interrupted && result == null) {
|
||||
try {
|
||||
synchronized (raceCache) {
|
||||
if (timeoutInMilliseconds == -1) {
|
||||
raceCache.wait();
|
||||
} else {
|
||||
long timeToWait = timeoutInMilliseconds-(System.currentTimeMillis()-start);
|
||||
if (timeToWait > 0) {
|
||||
raceCache.wait(timeToWait);
|
||||
if (result == null) {
|
||||
synchronized (raceCache) {
|
||||
// try again while under raceCache's monitor; otherwise we may miss a notification
|
||||
result = raceCache.get(raceId);
|
||||
while ((timeoutInMilliseconds == -1 || System.currentTimeMillis()-start < timeoutInMilliseconds) && !interrupted && result == null) {
|
||||
try {
|
||||
if (timeoutInMilliseconds == -1) {
|
||||
raceCache.wait();
|
||||
} else {
|
||||
long timeToWait = timeoutInMilliseconds-(System.currentTimeMillis()-start);
|
||||
if (timeToWait > 0) {
|
||||
raceCache.wait(timeToWait);
|
||||
}
|
||||
}
|
||||
result = raceCache.get(raceId);
|
||||
} catch (InterruptedException e) {
|
||||
interrupted = true;
|
||||
}
|
||||
}
|
||||
result = raceCache.get(raceId);
|
||||
} catch (InterruptedException e) {
|
||||
interrupted = true;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
Reference in new issue
Block a user