001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.components.thread;
018:
019: /**
020: * The ThreadPool interface gives access to methods needed to inspect and use
021: * of a pool of threads
022: *
023: * @author <a href="mailto:giacomo.at.apache.org">Giacomo Pati</a>
024: * @version CVS $Id: ThreadPool.java 56702 2004-11-05 22:52:05Z giacomo $
025: */
026: public interface ThreadPool {
027: //~ Instance fields --------------------------------------------------------
028:
029: /** ThreadPool block policy ABORT */
030: String POLICY_ABORT = "ABORT";
031:
032: /** ThreadPool block policy DISCARD */
033: String POLICY_DISCARD = "DISCARD";
034:
035: /** ThreadPool block policy DISCARD-OLDEST */
036: String POLICY_DISCARD_OLDEST = "DISCARDOLDEST";
037:
038: /** ThreadPool block policy RUN */
039: String POLICY_RUN = "RUN";
040:
041: /** ThreadPool block policy WAIT */
042: String POLICY_WAIT = "WAIT";
043:
044: /** The Role name */
045: String ROLE = ThreadPool.class.getName();
046:
047: //~ Methods ----------------------------------------------------------------
048:
049: /**
050: * The blocking policy used
051: *
052: * @return DOCUMENT ME!
053: */
054: String getBlockPolicy();
055:
056: /**
057: * How long will a thread in this pool be idle before it is allowed to be
058: * garbage collected
059: *
060: * @return maximum idle time
061: */
062: long getKeepAliveTime();
063:
064: /**
065: * How many threads are in this pool at maximum
066: *
067: * @return maximum size of pool
068: */
069: int getMaximumPoolSize();
070:
071: /**
072: * Maximum size of the queue
073: *
074: * @return current size of queue
075: */
076: int getMaximumQueueSize();
077:
078: /**
079: * How many threads are in this pool at minimum
080: *
081: * @return minimum size of pool
082: */
083: int getMinimumPoolSize();
084:
085: /**
086: * The Name of this thread pool
087: *
088: * @return The name
089: */
090: String getName();
091:
092: /**
093: * How many threads are currently in this pool
094: *
095: * @return current size of pool
096: */
097: int getPoolSize();
098:
099: /**
100: * Get the thread priority used by this pool
101: *
102: * @return current size of queue
103: */
104: int getPriority();
105:
106: /**
107: * Current size of the queue.
108: *
109: * @return current size of queue. If the size of the queue is not
110: * maintained by an implementation -1 should be returned.
111: */
112: int getQueueSize();
113:
114: /**
115: * Whether this ThreadPool has a queue
116: *
117: * @return Returns true if this ThreadPool has a queue
118: */
119: boolean isQueued();
120:
121: /**
122: * Returns true if a shutDown method has succeeded in terminating all
123: * threads
124: *
125: * @return Whether a shutDown method has succeeded in terminating all
126: * threads
127: */
128: boolean isTerminatedAfterShutdown();
129:
130: /**
131: * Execute a command using this pool
132: *
133: * @param command a {@link Runnable} to execute
134: *
135: * @throws InterruptedException In case of interruption
136: */
137: void execute(Runnable command) throws InterruptedException;
138:
139: /**
140: * Terminates all threads possibly awaiting processing all elements
141: * currently in queue.
142: */
143: void shutdown();
144: }
|