added synchronization to fix bug 1046 (ConcurrentModificationException while loading score corrections and at the same time attaching a tracked race)

This commit is contained in:
Axel Uhl
2012-11-15 15:38:51 +01:00
parent 34e40fa4bd
commit 1416fbd0d6
3 changed files with 95 additions and 49 deletions
@@ -9,4 +9,5 @@
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="com.sap.sailing.domain.swisstimingadapter.persistence.StoreAndForward"/>
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="3500 3501"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="com.sap.sailing.domain.swisstimingadapter.persistence"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Djava.util.logging.config.file=${project_loc:com.sap.sailing.server}/../target/configuration/logging_debug.properties"/>
</launchConfiguration>
@@ -280,11 +280,27 @@ public class StoreAndForward implements Runnable {
SailMasterMessage message = swissTimingFactory.createMessage(messageAndOptionalSequenceNumber.getA(), lastMessageCount);
swissTimingAdapterPersistence.storeSailMasterMessage(message);
synchronized (this) {
for (OutputStream os : streamsToForwardTo) {
for (OutputStream os : new ArrayList<OutputStream>(streamsToForwardTo)) {
// write the sequence number of the message into the stream before actually writing the
// SwissTiming message
try {
// TODO if forwarding to os doesn't work, e.g., because the socket was closed or the client died, remove os from streamsToForwardTo and the socket from socketsToForwardTo
transceiver.sendMessage(message, os);
transceiver.sendMessage(message, os);
} catch (Throwable e) {
int i=streamsToForwardTo.indexOf(os);
try {
os.close();
} catch (Throwable t) {
logger.throwing(StoreAndForward.class.getName(), "run", t);
}
streamsToForwardTo.remove(os);
Socket s = socketsToForwardTo.remove(i);
try {
s.close();
} catch (Throwable t) {
logger.throwing(StoreAndForward.class.getName(), "run", t);
}
}
}
}
if (!stopped) {