Skip to content

Commit d634714

Browse files
committed
Rework after review
Copy the clients into a local list
1 parent 23a1055 commit d634714

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/main/java/org/java_websocket/server/WebSocketServer.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -924,16 +924,18 @@ private void doBroadcast(Object data, Collection<WebSocket> clients) {
924924
return;
925925
}
926926
Map<Draft, List<Framedata>> draftFrames = new HashMap<Draft, List<Framedata>>();
927+
List<WebSocket> clientCopy;
927928
synchronized (clients) {
928-
for (WebSocket client : clients) {
929-
if (client != null) {
930-
Draft draft = client.getDraft();
931-
fillFrames(draft, draftFrames, sData, bData);
932-
try {
933-
client.sendFrame(draftFrames.get(draft));
934-
} catch (WebsocketNotConnectedException e) {
935-
//Ignore this exception in this case
936-
}
929+
clientCopy = new ArrayList<WebSocket>(clients);
930+
}
931+
for (WebSocket client : clientCopy) {
932+
if (client != null) {
933+
Draft draft = client.getDraft();
934+
fillFrames(draft, draftFrames, sData, bData);
935+
try {
936+
client.sendFrame(draftFrames.get(draft));
937+
} catch (WebsocketNotConnectedException e) {
938+
//Ignore this exception in this case
937939
}
938940
}
939941
}

0 commit comments

Comments
 (0)