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,9 +314,10 @@ public class CallbackServer implements Runnable {
* @return int * @return int
*/ */
public int getSize() { public int getSize() {
int size = this.javascript.size(); synchronized(this) {
//System.out.println("getSize() = " + size); int size = this.javascript.size();
return size; return size;
}
} }
/** /**
@ -325,17 +326,16 @@ public class CallbackServer implements Runnable {
* @return String * @return String
*/ */
public String getJavascript() { public String getJavascript() {
if (this.javascript.size() == 0) { synchronized(this) {
return null; if (this.javascript.size() == 0) {
} return null;
String statement = this.javascript.remove(0); }
//System.out.println("CallbackServer.getJavascript() = " + statement); String statement = this.javascript.remove(0);
if (this.javascript.size() == 0) { if (this.javascript.size() == 0) {
synchronized (this) { this.empty = true;
this.empty = true; }
} return statement;
} }
return statement;
} }
/** /**
@ -344,12 +344,11 @@ 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+")"); synchronized (this) {
this.javascript.add(statement); this.javascript.add(statement);
synchronized (this) { this.empty = false;
this.empty = false; this.notify();
this.notify(); }
}
} }
/* The Following code has been modified from original implementation of URLEncoder */ /* The Following code has been modified from original implementation of URLEncoder */