Repository: zeppelin Updated Branches: refs/heads/master 9367f87b3 -> 2e5900808
[ZEPPELIN-2724] Move NotebookSocket.send() out of synchronized block ### What is this PR for? This PR tries to address https://issues.apache.org/jira/browse/ZEPPELIN-2724. ### What type of PR is it? Bug Fix ### Todos * [x] - Move NotebookSocket.send() out of synchronized block * [x] - Waits for verification this actually fixes the problem ### What is the Jira issue? https://issues.apache.org/jira/browse/ZEPPELIN-2724 ### Questions: * Does the licenses files need update? no * Is there breaking changes for older versions? no * Does this needs documentation? no Author: Lee moon soo <m...@apache.org> Closes #2465 from Leemoonsoo/ZEPPELIN-2724 and squashes the following commits: a20a57b [Lee moon soo] initialize with empty list c01246c [Lee moon soo] Move NotebookSocket.send() out of synchronized block Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/2e590080 Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/2e590080 Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/2e590080 Branch: refs/heads/master Commit: 2e590080893e427cc64c4c1acc228b80c8705fcd Parents: 9367f87 Author: Lee moon soo <m...@apache.org> Authored: Thu Jul 6 15:56:33 2017 +0900 Committer: Lee moon soo <m...@apache.org> Committed: Wed Jul 26 18:00:48 2017 -0700 ---------------------------------------------------------------------- .../apache/zeppelin/socket/NotebookServer.java | 39 +++++++++++--------- 1 file changed, 22 insertions(+), 17 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zeppelin/blob/2e590080/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java ---------------------------------------------------------------------- diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java b/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java index 14e4983..61bc536 100644 --- a/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java +++ b/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java @@ -473,40 +473,45 @@ public class NotebookServer extends WebSocketServlet } private void broadcast(String noteId, Message m) { + List<NotebookSocket> socketsToBroadcast = Collections.emptyList(); 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 = Collections.emptyList(); 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); } } }