diff src/org/eclipse/jetty/server/Server.java @ 865:6b210bb66c63

remove ThreadPool
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 02 Oct 2016 20:38:06 -0600
parents e21ca9878a10
children 4f5547d29192
line wrap: on
line diff
--- a/src/org/eclipse/jetty/server/Server.java	Sun Oct 02 16:17:38 2016 -0600
+++ b/src/org/eclipse/jetty/server/Server.java	Sun Oct 02 20:38:06 2016 -0600
@@ -21,6 +21,9 @@
 import java.io.IOException;
 import java.net.InetSocketAddress;
 import java.util.Enumeration;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
@@ -40,9 +43,7 @@
 import org.eclipse.jetty.util.component.LifeCycle;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.eclipse.jetty.util.thread.QueuedThreadPool;
 import org.eclipse.jetty.util.thread.ShutdownThread;
-import org.eclipse.jetty.util.thread.ThreadPool;
 
 /* ------------------------------------------------------------ */
 /** Jetty HTTP Servlet Server.
@@ -60,7 +61,7 @@
 	private static final String __version = "8";
 
 	private final AttributesMap _attributes = new AttributesMap();
-	private final ThreadPool _threadPool;
+	private final ThreadPoolExecutor _threadPool;
 	private Connector[] _connectors;
 	private boolean _sendServerVersion = true; //send Server: header
 	private boolean _sendDateHeader = false; //send Date: header
@@ -83,7 +84,7 @@
 		connector.setPort(port);
 		setConnectors(new Connector[]{connector});
 
-		_threadPool = new QueuedThreadPool();
+		_threadPool = new ThreadPoolExecutor(256, 256, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
 		addBean(_threadPool);
 	}
 
@@ -165,7 +166,7 @@
 	/**
 	 * @return Returns the threadPool.
 	 */
-	public ThreadPool getThreadPool()
+	public ThreadPoolExecutor getThreadPool()
 	{
 		return _threadPool;
 	}
@@ -358,7 +359,8 @@
 	/* ------------------------------------------------------------ */
 	public void join() throws InterruptedException
 	{
-		getThreadPool().join();
+//		getThreadPool().join();
+		_threadPool.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
 	}
 
 	/* ------------------------------------------------------------ */
@@ -515,6 +517,16 @@
 		public void setShutdown(boolean shutdown);
 	}
 
+
+	public final boolean isLowOnThreads()
+	{
+		ThreadPoolExecutor tpe = getThreadPool();
+		// getActiveCount() locks the thread pool, so execute it last
+		return tpe.getPoolSize() == tpe.getMaximumPoolSize() &&
+				tpe.getQueue().size() >= tpe.getPoolSize() - tpe.getActiveCount();
+	}
+
+
 	/* ------------------------------------------------------------ */
 	public static void main(String...args) throws Exception
 	{