1 //
2 // ========================================================================
3 // Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd.
4 // ------------------------------------------------------------------------
5 // All rights reserved. This program and the accompanying materials
6 // are made available under the terms of the Eclipse Public License v1.0
7 // and Apache License v2.0 which accompanies this distribution.
8 //
9 // The Eclipse Public License is available at
10 // http://www.eclipse.org/legal/epl-v10.html
11 //
12 // The Apache License v2.0 is available at
13 // http://www.opensource.org/licenses/apache2.0.php
14 //
15 // You may elect to redistribute this code under either of these licenses.
16 // ========================================================================
17 //
18
19 package org.eclipse.jetty.util.thread;
20
21 import java.util.concurrent.Executor;
22
23 import org.eclipse.jetty.util.annotation.ManagedAttribute;
24 import org.eclipse.jetty.util.annotation.ManagedObject;
25 import org.eclipse.jetty.util.component.LifeCycle;
26
27 /* ------------------------------------------------------------ */
28 /** ThreadPool.
29 *
30 * A specialization of Executor interface that provides reporting methods (eg {@link #getThreads()})
31 * and the option of configuration methods (e.g. @link {@link SizedThreadPool#setMaxThreads(int)}).
32 *
33 */
34 @ManagedObject("Pool of Threads")
35 public interface ThreadPool extends Executor
36 {
37 /* ------------------------------------------------------------ */
38 /**
39 * Blocks until the thread pool is {@link LifeCycle#stop stopped}.
40 * @throws InterruptedException if thread was interrupted
41 */
42 public void join() throws InterruptedException;
43
44 /* ------------------------------------------------------------ */
45 /**
46 * @return The total number of threads currently in the pool
47 */
48 @ManagedAttribute("number of threads in pool")
49 public int getThreads();
50
51 /* ------------------------------------------------------------ */
52 /**
53 * @return The number of idle threads in the pool
54 */
55 @ManagedAttribute("number of idle threads in pool")
56 public int getIdleThreads();
57
58 /* ------------------------------------------------------------ */
59 /**
60 * @return True if the pool is low on threads
61 */
62 @ManagedAttribute("indicates the pool is low on available threads")
63 public boolean isLowOnThreads();
64
65
66 /* ------------------------------------------------------------ */
67 /* ------------------------------------------------------------ */
68 public interface SizedThreadPool extends ThreadPool
69 {
70 public int getMinThreads();
71 public int getMaxThreads();
72 public void setMinThreads(int threads);
73 public void setMaxThreads(int threads);
74 }
75 }