From 1d4c6eda49b4e0b0bcd847f00e3a5d025d37e7a5 Mon Sep 17 00:00:00 2001 From: "James M.Z" Date: Fri, 20 Jan 2017 13:48:08 +0800 Subject: [PATCH 1/2] Reverted to the last version for talk.java, since it will be processed in smalltalk.java --- src/tinystruct/examples/talk.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tinystruct/examples/talk.java b/src/tinystruct/examples/talk.java index 6897252..61b607e 100644 --- a/src/tinystruct/examples/talk.java +++ b/src/tinystruct/examples/talk.java @@ -125,11 +125,11 @@ public void run() { * @throws IOException */ public final String update(final String sessionId) throws ApplicationException, IOException { - Builder message = null; + Builder message; Queue messages; synchronized (this.list) { messages = this.list.get(sessionId); - while(messages != null && (message = messages.poll()) == null) { + while((message = messages.poll()) == null) { try { this.list.wait(TIMEOUT); } catch (InterruptedException e) { @@ -137,7 +137,7 @@ public final String update(final String sessionId) throws ApplicationException, } } - return message != null ? message.toString() : ""; + return message.toString(); } } From ff77c5b6d8e26acecf598a110e20072f976f0a14 Mon Sep 17 00:00:00 2001 From: "James M.Z" Date: Fri, 20 Jan 2017 13:52:08 +0800 Subject: [PATCH 2/2] Reduce the time to get the list by meeting code to save performance. --- src/tinystruct/examples/smalltalk.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/tinystruct/examples/smalltalk.java b/src/tinystruct/examples/smalltalk.java index daaa3a6..ab4bc4e 100644 --- a/src/tinystruct/examples/smalltalk.java +++ b/src/tinystruct/examples/smalltalk.java @@ -213,7 +213,8 @@ public String update() throws ApplicationException, IOException { public String update(String meetingCode, String sessionId) throws ApplicationException, IOException { String error = "{ \"error\": \"expired\" }"; if (this.meetings.containsKey(meetingCode)) { - if(sessions.get(meetingCode) != null && sessions.get(meetingCode).contains(sessionId)) { + List list; + if((list = sessions.get(meetingCode)) != null && list.contains(sessionId)) { return this.update(sessionId); } error = "{ \"error\": \"session-timeout\" }"; @@ -330,7 +331,7 @@ public void sessionDestroyed(HttpSessionEvent arg0) { Queue messages; List session_ids; - synchronized (this.meetings) { + synchronized (this.meetings) { if((session_ids = this.sessions.get(meetingCode)) != null) { session_ids.remove(arg0.getSession().getId()); }