Mercurial Hosting > luan
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 864:e21ca9878a10 | 865:6b210bb66c63 |
|---|---|
| 19 package org.eclipse.jetty.server; | 19 package org.eclipse.jetty.server; |
| 20 | 20 |
| 21 import java.io.IOException; | 21 import java.io.IOException; |
| 22 import java.net.InetSocketAddress; | 22 import java.net.InetSocketAddress; |
| 23 import java.util.Enumeration; | 23 import java.util.Enumeration; |
| 24 import java.util.concurrent.LinkedBlockingQueue; | |
| 25 import java.util.concurrent.ThreadPoolExecutor; | |
| 26 import java.util.concurrent.TimeUnit; | |
| 24 | 27 |
| 25 import javax.servlet.ServletException; | 28 import javax.servlet.ServletException; |
| 26 import javax.servlet.http.HttpServletRequest; | 29 import javax.servlet.http.HttpServletRequest; |
| 27 import javax.servlet.http.HttpServletResponse; | 30 import javax.servlet.http.HttpServletResponse; |
| 28 | 31 |
| 38 import org.eclipse.jetty.util.URIUtil; | 41 import org.eclipse.jetty.util.URIUtil; |
| 39 import org.eclipse.jetty.util.component.Destroyable; | 42 import org.eclipse.jetty.util.component.Destroyable; |
| 40 import org.eclipse.jetty.util.component.LifeCycle; | 43 import org.eclipse.jetty.util.component.LifeCycle; |
| 41 import org.slf4j.Logger; | 44 import org.slf4j.Logger; |
| 42 import org.slf4j.LoggerFactory; | 45 import org.slf4j.LoggerFactory; |
| 43 import org.eclipse.jetty.util.thread.QueuedThreadPool; | |
| 44 import org.eclipse.jetty.util.thread.ShutdownThread; | 46 import org.eclipse.jetty.util.thread.ShutdownThread; |
| 45 import org.eclipse.jetty.util.thread.ThreadPool; | |
| 46 | 47 |
| 47 /* ------------------------------------------------------------ */ | 48 /* ------------------------------------------------------------ */ |
| 48 /** Jetty HTTP Servlet Server. | 49 /** Jetty HTTP Servlet Server. |
| 49 * This class is the main class for the Jetty HTTP Servlet server. | 50 * This class is the main class for the Jetty HTTP Servlet server. |
| 50 * It aggregates Connectors (HTTP request receivers) and request Handlers. | 51 * It aggregates Connectors (HTTP request receivers) and request Handlers. |
| 58 private static final Logger LOG = LoggerFactory.getLogger(Server.class); | 59 private static final Logger LOG = LoggerFactory.getLogger(Server.class); |
| 59 | 60 |
| 60 private static final String __version = "8"; | 61 private static final String __version = "8"; |
| 61 | 62 |
| 62 private final AttributesMap _attributes = new AttributesMap(); | 63 private final AttributesMap _attributes = new AttributesMap(); |
| 63 private final ThreadPool _threadPool; | 64 private final ThreadPoolExecutor _threadPool; |
| 64 private Connector[] _connectors; | 65 private Connector[] _connectors; |
| 65 private boolean _sendServerVersion = true; //send Server: header | 66 private boolean _sendServerVersion = true; //send Server: header |
| 66 private boolean _sendDateHeader = false; //send Date: header | 67 private boolean _sendDateHeader = false; //send Date: header |
| 67 private int _graceful=0; | 68 private int _graceful=0; |
| 68 private boolean _stopAtShutdown; | 69 private boolean _stopAtShutdown; |
| 81 | 82 |
| 82 Connector connector=new SelectChannelConnector(); | 83 Connector connector=new SelectChannelConnector(); |
| 83 connector.setPort(port); | 84 connector.setPort(port); |
| 84 setConnectors(new Connector[]{connector}); | 85 setConnectors(new Connector[]{connector}); |
| 85 | 86 |
| 86 _threadPool = new QueuedThreadPool(); | 87 _threadPool = new ThreadPoolExecutor(256, 256, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>()); |
| 87 addBean(_threadPool); | 88 addBean(_threadPool); |
| 88 } | 89 } |
| 89 | 90 |
| 90 | 91 |
| 91 /* ------------------------------------------------------------ */ | 92 /* ------------------------------------------------------------ */ |
| 163 | 164 |
| 164 /* ------------------------------------------------------------ */ | 165 /* ------------------------------------------------------------ */ |
| 165 /** | 166 /** |
| 166 * @return Returns the threadPool. | 167 * @return Returns the threadPool. |
| 167 */ | 168 */ |
| 168 public ThreadPool getThreadPool() | 169 public ThreadPoolExecutor getThreadPool() |
| 169 { | 170 { |
| 170 return _threadPool; | 171 return _threadPool; |
| 171 } | 172 } |
| 172 | 173 |
| 173 /** | 174 /** |
| 356 | 357 |
| 357 | 358 |
| 358 /* ------------------------------------------------------------ */ | 359 /* ------------------------------------------------------------ */ |
| 359 public void join() throws InterruptedException | 360 public void join() throws InterruptedException |
| 360 { | 361 { |
| 361 getThreadPool().join(); | 362 // getThreadPool().join(); |
| 363 _threadPool.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS); | |
| 362 } | 364 } |
| 363 | 365 |
| 364 /* ------------------------------------------------------------ */ | 366 /* ------------------------------------------------------------ */ |
| 365 | 367 |
| 366 /* ------------------------------------------------------------ */ | 368 /* ------------------------------------------------------------ */ |
| 513 public interface Graceful extends Handler | 515 public interface Graceful extends Handler |
| 514 { | 516 { |
| 515 public void setShutdown(boolean shutdown); | 517 public void setShutdown(boolean shutdown); |
| 516 } | 518 } |
| 517 | 519 |
| 520 | |
| 521 public final boolean isLowOnThreads() | |
| 522 { | |
| 523 ThreadPoolExecutor tpe = getThreadPool(); | |
| 524 // getActiveCount() locks the thread pool, so execute it last | |
| 525 return tpe.getPoolSize() == tpe.getMaximumPoolSize() && | |
| 526 tpe.getQueue().size() >= tpe.getPoolSize() - tpe.getActiveCount(); | |
| 527 } | |
| 528 | |
| 529 | |
| 518 /* ------------------------------------------------------------ */ | 530 /* ------------------------------------------------------------ */ |
| 519 public static void main(String...args) throws Exception | 531 public static void main(String...args) throws Exception |
| 520 { | 532 { |
| 521 System.err.println(getVersion()); | 533 System.err.println(getVersion()); |
| 522 } | 534 } |
