View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2013 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       */
41      public void join() throws InterruptedException;
42  
43      /* ------------------------------------------------------------ */
44      /**
45       * @return The total number of threads currently in the pool
46       */
47      @ManagedAttribute("number of threads in pool")
48      public int getThreads();
49  
50      /* ------------------------------------------------------------ */
51      /**
52       * @return The number of idle threads in the pool
53       */
54      @ManagedAttribute("number of idle threads in pool")
55      public int getIdleThreads();
56      
57      /* ------------------------------------------------------------ */
58      /**
59       * @return True if the pool is low on threads
60       */
61      @ManagedAttribute("indicates the pool is low on available threads")
62      public boolean isLowOnThreads();
63      
64  
65      /* ------------------------------------------------------------ */
66      /* ------------------------------------------------------------ */
67      public interface SizedThreadPool extends ThreadPool
68      {
69          public int getMinThreads();
70          public int getMaxThreads();
71          public void setMinThreads(int threads);
72          public void setMaxThreads(int threads);
73      }
74  }