Move NotebookSocket.send() out of synchronized block

This commit is contained in:
Lee moon soo 2017-07-06 13:22:01 +09:00
parent 2842251b77
commit c01246c246

View file

@ -483,40 +483,45 @@ public class NotebookServer extends WebSocketServlet
}
private void broadcast(String noteId, Message m) {
List<NotebookSocket> socketsToBroadcast;
synchronized (noteSocketMap) {
broadcastToWatchers(noteId, StringUtils.EMPTY, m);
List<NotebookSocket> socketLists = noteSocketMap.get(noteId);
if (socketLists == null || socketLists.size() == 0) {
return;
}
LOG.debug("SEND >> " + m);
for (NotebookSocket conn : socketLists) {
try {
conn.send(serializeMessage(m));
} catch (IOException e) {
LOG.error("socket error", e);
}
socketsToBroadcast = new ArrayList<>(socketLists);
}
LOG.debug("SEND >> " + m);
for (NotebookSocket conn : socketsToBroadcast) {
try {
conn.send(serializeMessage(m));
} catch (IOException e) {
LOG.error("socket error", e);
}
}
}
private void broadcastExcept(String noteId, Message m, NotebookSocket exclude) {
List<NotebookSocket> socketsToBroadcast;
synchronized (noteSocketMap) {
broadcastToWatchers(noteId, StringUtils.EMPTY, m);
List<NotebookSocket> socketLists = noteSocketMap.get(noteId);
if (socketLists == null || socketLists.size() == 0) {
return;
}
LOG.debug("SEND >> " + m);
for (NotebookSocket conn : socketLists) {
if (exclude.equals(conn)) {
continue;
}
try {
conn.send(serializeMessage(m));
} catch (IOException e) {
LOG.error("socket error", e);
}
socketsToBroadcast = new ArrayList<>(socketLists);
}
LOG.debug("SEND >> " + m);
for (NotebookSocket conn : socketsToBroadcast) {
if (exclude.equals(conn)) {
continue;
}
try {
conn.send(serializeMessage(m));
} catch (IOException e) {
LOG.error("socket error", e);
}
}
}