KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > dream > control > activity > task > thread > ThreadPoolController


1 /**
2  * Dream
3  * Copyright (C) 2003-2004 INRIA Rhone-Alpes
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Contact: dream@objectweb.org
20  *
21  * Initial developer(s): Matthieu Leclercq
22  * Contributor(s):
23  */

24
25 package org.objectweb.dream.control.activity.task.thread;
26
27 import org.objectweb.fractal.api.control.IllegalLifeCycleException;
28
29 /**
30  * Controller interface for thread pools. It allows increasing or decreasing the
31  * number of threads in the pool.
32  */

33 public interface ThreadPoolController
34 {
35
36   /**
37    * The default timeout.
38    *
39    * @see #setWaitTimeout(long)
40    */

41   long DEFAULT_WAIT_TIMEOUT = 2000;
42
43   /**
44    * Sets the capacity of the pool. The capacity of the pool is the maximum
45    * number of currently executing threads. If the capacity is reduced,
46    * currently executing threads are not stopped. As a consequence, the number
47    * of executing threads may temporarily exceed the capacity.
48    *
49    * @param i the capacity of the pool.
50    */

51   void setCapacity(int i);
52
53   /**
54    * Returns the capacity of the pool.
55    *
56    * @return the capacity of the pool.
57    */

58   int getCapacity();
59
60   /**
61    * Sets the timeout while a "dying" thread can be "reactivated" and reused,
62    * rather than create a new thread.
63    *
64    * @param millis timeout in millisecond.
65    */

66   void setWaitTimeout(long millis);
67
68   /**
69    * Returns the timeout while "dying" thread can be "reactivated".
70    *
71    * @return timeout in millisecond.
72    */

73   long getWaitTimeout();
74
75   /**
76    * Returns the number of currently active threads.
77    *
78    * @return the number of currently active threads.
79    */

80   int getNbActiveThreads();
81
82   /**
83    * Adds threads in the pool. If the thread pool is stopping (see
84    * {@link org.objectweb.dream.control.activity.task.TaskLifeCycleController})
85    * the added threads are immediatly interrupted.
86    *
87    * @param i the number of thread to add.
88    * @throws ThreadPoolOverflowException if
89    * <code>getNbActiveThread() + i &gt; getCapacity() </code>
90    * @throws IllegalLifeCycleException if the component this interface belong
91    * has a lifecycle controller and is in the
92    * {@link org.objectweb.fractal.api.control.LifeCycleController#STOPPED}
93    * state.
94    */

95   void addThreads(int i) throws ThreadPoolOverflowException,
96       IllegalLifeCycleException;
97
98   /**
99    * Removes threads from the pool. The threads are removed in a FIFO order.
100    * This method is not synchronized with the end of the removed threads. This
101    * means that the method may return before the end of the removed threads.
102    *
103    * @param i the number of thread to remove.
104    * @throws IllegalLifeCycleException if the component this interface belong
105    * has a lifecycle controller and is in the
106    * {@link org.objectweb.fractal.api.control.LifeCycleController#STOPPED}
107    * state.
108    */

109   void removeThreads(int i) throws IllegalLifeCycleException;
110
111 }
Popular Tags