Fix CB-135 Multithreaded access on CallbackServer javascript object.

This commit is contained in:
Bryce Curtis 2012-01-06 22:23:49 -06:00
parent bc309c9f00
commit 8db5e06c62

View File

@ -314,10 +314,11 @@ public class CallbackServer implements Runnable {
* @return int * @return int
*/ */
public int getSize() { public int getSize() {
synchronized(this) {
int size = this.javascript.size(); int size = this.javascript.size();
//System.out.println("getSize() = " + size);
return size; return size;
} }
}
/** /**
* Get the next JavaScript statement and remove from list. * Get the next JavaScript statement and remove from list.
@ -325,18 +326,17 @@ public class CallbackServer implements Runnable {
* @return String * @return String
*/ */
public String getJavascript() { public String getJavascript() {
synchronized(this) {
if (this.javascript.size() == 0) { if (this.javascript.size() == 0) {
return null; return null;
} }
String statement = this.javascript.remove(0); String statement = this.javascript.remove(0);
//System.out.println("CallbackServer.getJavascript() = " + statement);
if (this.javascript.size() == 0) { if (this.javascript.size() == 0) {
synchronized (this) {
this.empty = true; this.empty = true;
} }
}
return statement; return statement;
} }
}
/** /**
* Add a JavaScript statement to the list. * Add a JavaScript statement to the list.
@ -344,9 +344,8 @@ public class CallbackServer implements Runnable {
* @param statement * @param statement
*/ */
public void sendJavascript(String statement) { public void sendJavascript(String statement) {
//System.out.println("CallbackServer.sendJavascript("+statement+")");
this.javascript.add(statement);
synchronized (this) { synchronized (this) {
this.javascript.add(statement);
this.empty = false; this.empty = false;
this.notify(); this.notify();
} }