Removed dead code.

Change to WebServer's listener code to ensure that there is always a thread listening (we somehow ended up with no thread listening in some cases).
This commit is contained in:
wcrisman
2014-07-30 23:21:05 -07:00
parent cd0976ea2e
commit 12d99f8b4d
2 changed files with 14 additions and 10 deletions

View File

@@ -164,11 +164,11 @@ public class ThreadService {
singleThreadedContext = null; singleThreadedContext = null;
target.run(); target.run();
}//if// }//if//
else { // else {
Debug.log("A target must be provided in order to run a reusable thread."); // Debug.log("A target must be provided in order to run a reusable thread.");
}//else// // }//else//
}//try// }//try//
catch(Exception e) { catch(Throwable e) {
if(e instanceof InterruptedException) { if(e instanceof InterruptedException) {
return; return;
}//if// }//if//

View File

@@ -1723,13 +1723,14 @@ public class WebServer {
*/ */
private class NetworkListener implements Runnable { private class NetworkListener implements Runnable {
private Selector selector = null; private Selector selector = null;
private int maxThreadCount = 0;
private int activeThreadCount = 0;
private Iterator selectedKeys = null; private Iterator selectedKeys = null;
// private boolean hasListener = false; // private boolean hasListener = false;
private volatile boolean stop = true; private volatile boolean stop = true;
private volatile boolean hasRunnables = false; private volatile boolean hasRunnables = false;
private LiteList runnables = new LiteList(10, 20); private LiteList runnables = new LiteList(10, 20);
private int maxThreadCount = 0;
private int activeThreadCount = 0;
private int threadId = 1;
public NetworkListener(Selector selector, int maxThreadCount) { public NetworkListener(Selector selector, int maxThreadCount) {
this.selector = selector; this.selector = selector;
@@ -1752,6 +1753,9 @@ public class WebServer {
if(stop) { if(stop) {
stop = false; stop = false;
ThreadService.run(this); ThreadService.run(this);
// Thread t = new Thread(this);
// t.setName("Network Listener 1");
// t.start();
}//if// }//if//
}//start()// }//start()//
/** /**
@@ -1901,10 +1905,10 @@ public class WebServer {
try { try {
if(((SocketChannel) channel).isOpen()) { if(((SocketChannel) channel).isOpen()) {
synchronized(this) { synchronized(this) {
if(++activeThreadCount != maxThreadCount) { // if(++activeThreadCount != maxThreadCount) {
//Start another thread to take this thread's place.// //Start another thread to take this thread's place.//
ThreadService.run(this); ThreadService.run(this);
}//if// // }//if//
}//synchronized// }//synchronized//
if(isWrite) { if(isWrite) {
@@ -1958,13 +1962,13 @@ public class WebServer {
//Loop if the last thread to wait for a message couldn't start another thread due to the max number of threads allowed.// //Loop if the last thread to wait for a message couldn't start another thread due to the max number of threads allowed.//
synchronized(this) { synchronized(this) {
if(activeThreadCount-- != maxThreadCount) { // if(activeThreadCount-- != maxThreadCount) {
loop = false; loop = false;
if(requiresWakeup) { if(requiresWakeup) {
selector.wakeup(); selector.wakeup();
}//if// }//if//
}//if// // }//if//
}//synchronized// }//synchronized//
}//finally// }//finally//
}//else if// }//else if//