Fix concurrent collection modification issue in NetMarshalClient.
This commit is contained in:
parent
6edf85ce51
commit
548d11a35e
@ -18,6 +18,7 @@ import java.net.InetAddress;
|
|||||||
import java.net.MulticastSocket;
|
import java.net.MulticastSocket;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
@ -100,20 +101,27 @@ public class NetMarshalClient implements Closeable {
|
|||||||
fragmentSMM = new HashMap<>();
|
fragmentSMM = new HashMap<>();
|
||||||
fragmentMonitorThread = new Thread(() -> {
|
fragmentMonitorThread = new Thread(() -> {
|
||||||
int ageCheckTime = this.fragmentationOptions.maximumFragmentAge - 1;
|
int ageCheckTime = this.fragmentationOptions.maximumFragmentAge - 1;
|
||||||
|
ArrayList<Integer> idsToRemove = new ArrayList<>();
|
||||||
while (running) {
|
while (running) {
|
||||||
synchronized (this.fragmentationOptions) {
|
synchronized (this.fragmentationOptions) {
|
||||||
for (int c : fragmentRMM.keySet()) {
|
for (int c : fragmentRMM.keySet()) {
|
||||||
if (!fragmentRMM.get(c).plusSeconds(ageCheckTime).isAfter(LocalDateTime.now())) {
|
if (!fragmentRMM.get(c).plusSeconds(ageCheckTime).isAfter(LocalDateTime.now()))
|
||||||
fragmentRMM.remove(c);
|
idsToRemove.add(c);
|
||||||
fragmentReceiver.deletePacketFromRegistry(c);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
for (int c : idsToRemove) {
|
||||||
|
fragmentRMM.remove(c);
|
||||||
|
fragmentReceiver.deletePacketFromRegistry(c);
|
||||||
|
}
|
||||||
|
idsToRemove.clear();
|
||||||
for (int c : fragmentSMM.keySet()) {
|
for (int c : fragmentSMM.keySet()) {
|
||||||
if (!fragmentSMM.get(c).plusSeconds(ageCheckTime).isAfter(LocalDateTime.now())) {
|
if (!fragmentSMM.get(c).plusSeconds(ageCheckTime).isAfter(LocalDateTime.now()))
|
||||||
fragmentSMM.remove(c);
|
idsToRemove.add(c);
|
||||||
fragmentSender.deletePacketFromRegistry(c);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
for (int c : idsToRemove) {
|
||||||
|
fragmentSMM.remove(c);
|
||||||
|
fragmentSender.deletePacketFromRegistry(c);
|
||||||
|
}
|
||||||
|
idsToRemove.clear();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Thread.sleep(this.fragmentationOptions.maximumFragmentAge);
|
Thread.sleep(this.fragmentationOptions.maximumFragmentAge);
|
||||||
|
Loading…
Reference in New Issue
Block a user