comparison src/org/eclipse/jetty/server/Server.java @ 875:b9aa175d9a29

remove Server.getThreadPool()
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 04 Oct 2016 13:45:47 -0600
parents 4f5547d29192
children 2efdb98f3543
comparison
equal deleted inserted replaced
874:ad495e897c32 875:b9aa175d9a29
59 private static final Logger LOG = LoggerFactory.getLogger(Server.class); 59 private static final Logger LOG = LoggerFactory.getLogger(Server.class);
60 60
61 private static final String __version = "8"; 61 private static final String __version = "8";
62 62
63 private final AttributesMap _attributes = new AttributesMap(); 63 private final AttributesMap _attributes = new AttributesMap();
64 private final ThreadPoolExecutor _threadPool; 64 public final ThreadPoolExecutor threadPool;
65 private Connector[] _connectors; 65 private Connector[] _connectors;
66 private boolean _sendServerVersion = true; //send Server: header 66 private boolean _sendServerVersion = true; //send Server: header
67 private boolean _sendDateHeader = false; //send Date: header 67 private boolean _sendDateHeader = false; //send Date: header
68 private int _graceful=0; 68 private int _graceful=0;
69 private boolean _stopAtShutdown; 69 private boolean _stopAtShutdown;
82 82
83 Connector connector=new SelectChannelConnector(); 83 Connector connector=new SelectChannelConnector();
84 connector.setPort(port); 84 connector.setPort(port);
85 setConnectors(new Connector[]{connector}); 85 setConnectors(new Connector[]{connector});
86 86
87 _threadPool = new ThreadPoolExecutor(256, 256, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>()); 87 threadPool = new ThreadPoolExecutor(256, 256, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
88 } 88 }
89 89
90 90
91 /* ------------------------------------------------------------ */ 91 /* ------------------------------------------------------------ */
92 public static String getVersion() 92 public static String getVersion()
157 for (int i=0;i<connectors.length;i++) 157 for (int i=0;i<connectors.length;i++)
158 connectors[i].setServer(this); 158 connectors[i].setServer(this);
159 } 159 }
160 160
161 _connectors = connectors; 161 _connectors = connectors;
162 }
163
164 /* ------------------------------------------------------------ */
165 /**
166 * @return Returns the threadPool.
167 */
168 public ThreadPoolExecutor getThreadPool()
169 {
170 return _threadPool;
171 } 162 }
172 163
173 /** 164 /**
174 * @return true if {@link #dumpStdErr()} is called after starting 165 * @return true if {@link #dumpStdErr()} is called after starting
175 */ 166 */
281 { 272 {
282 for (int i=_connectors.length;i-->0;) 273 for (int i=_connectors.length;i-->0;)
283 try{_connectors[i].stop();}catch(Throwable e){mex.add(e);} 274 try{_connectors[i].stop();}catch(Throwable e){mex.add(e);}
284 } 275 }
285 276
286 _threadPool.shutdownNow(); 277 threadPool.shutdownNow();
287 278
288 try {super.doStop(); } catch(Throwable e) { mex.add(e);} 279 try {super.doStop(); } catch(Throwable e) { mex.add(e);}
289 280
290 mex.ifExceptionThrow(); 281 mex.ifExceptionThrow();
291 282
358 349
359 350
360 /* ------------------------------------------------------------ */ 351 /* ------------------------------------------------------------ */
361 public void join() throws InterruptedException 352 public void join() throws InterruptedException
362 { 353 {
363 // getThreadPool().join(); 354 threadPool.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
364 _threadPool.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
365 } 355 }
366 356
367 /* ------------------------------------------------------------ */ 357 /* ------------------------------------------------------------ */
368 358
369 /* ------------------------------------------------------------ */ 359 /* ------------------------------------------------------------ */
519 } 509 }
520 510
521 511
522 public final boolean isLowOnThreads() 512 public final boolean isLowOnThreads()
523 { 513 {
524 ThreadPoolExecutor tpe = getThreadPool();
525 // getActiveCount() locks the thread pool, so execute it last 514 // getActiveCount() locks the thread pool, so execute it last
526 return tpe.getPoolSize() == tpe.getMaximumPoolSize() && 515 return threadPool.getPoolSize() == threadPool.getMaximumPoolSize() &&
527 tpe.getQueue().size() >= tpe.getPoolSize() - tpe.getActiveCount(); 516 threadPool.getQueue().size() >= threadPool.getPoolSize() - threadPool.getActiveCount();
528 } 517 }
529 518
530 519
531 /* ------------------------------------------------------------ */ 520 /* ------------------------------------------------------------ */
532 public static void main(String...args) throws Exception 521 public static void main(String...args) throws Exception