Fix concurrent collection modification issue in NetMarshalClient.

This commit is contained in:
Captain ALM 2023-06-11 15:19:37 +01:00
parent 6edf85ce51
commit da7a3cb976
Signed by: alfred
GPG Key ID: 4E4ADD02609997B1

View File

@ -18,6 +18,7 @@ import java.net.InetAddress;
import java.net.MulticastSocket;
import java.net.Socket;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Queue;
@ -100,20 +101,27 @@ public class NetMarshalClient implements Closeable {
fragmentSMM = new HashMap<>();
fragmentMonitorThread = new Thread(() -> {
int ageCheckTime = this.fragmentationOptions.maximumFragmentAge - 1;
ArrayList<Integer> idsToRemove = new ArrayList<>();
while (running) {
synchronized (this.fragmentationOptions) {
for (int c : fragmentRMM.keySet()) {
if (!fragmentRMM.get(c).plusSeconds(ageCheckTime).isAfter(LocalDateTime.now())) {
if (!fragmentRMM.get(c).plusSeconds(ageCheckTime).isAfter(LocalDateTime.now()))
idsToRemove.add(c);
}
for (int c : idsToRemove) {
fragmentRMM.remove(c);
fragmentReceiver.deletePacketFromRegistry(c);
}
}
idsToRemove.clear();
for (int c : fragmentSMM.keySet()) {
if (!fragmentSMM.get(c).plusSeconds(ageCheckTime).isAfter(LocalDateTime.now())) {
if (!fragmentSMM.get(c).plusSeconds(ageCheckTime).isAfter(LocalDateTime.now()))
idsToRemove.add(c);
}
for (int c : idsToRemove) {
fragmentSMM.remove(c);
fragmentSender.deletePacketFromRegistry(c);
}
}
idsToRemove.clear();
}
try {
Thread.sleep(this.fragmentationOptions.maximumFragmentAge);