org.eclipse.jetty.server.Server
+ * {@link LifeCycle} interfaces so that it may be used by the Jetty {@code org.eclipse.jetty.server.Server}
+ *
+ * @deprecated use {@link ExecutorSizedThreadPool} instead
*/
+@Deprecated
public class ExecutorThreadPool extends AbstractLifeCycle implements ThreadPool, LifeCycle
{
private static final Logger LOG = Log.getLogger(ExecutorThreadPool.class);
private final ExecutorService _executor;
- /* ------------------------------------------------------------ */
public ExecutorThreadPool(ExecutorService executor)
{
_executor = executor;
}
- /* ------------------------------------------------------------ */
/**
* Wraps an {@link ThreadPoolExecutor}.
* Max pool size is 256, pool thread timeout after 60 seconds and
@@ -59,74 +59,70 @@ public class ExecutorThreadPool extends AbstractLifeCycle implements ThreadPool,
{
// Using an unbounded queue makes the maxThreads parameter useless
// Refer to ThreadPoolExecutor javadocs for details
- this(new ThreadPoolExecutor(256, 256, 60, TimeUnit.SECONDS, new LinkedBlockingQueueA pool for threads.
+ *A specialization of Executor interface that provides reporting methods (eg {@link #getThreads()}) + * and the option of configuration methods (e.g. @link {@link SizedThreadPool#setMaxThreads(int)}).
*/ @ManagedObject("Pool of Threads") public interface ThreadPool extends Executor { - /* ------------------------------------------------------------ */ /** * Blocks until the thread pool is {@link LifeCycle#stop stopped}. + * * @throws InterruptedException if thread was interrupted */ public void join() throws InterruptedException; - /* ------------------------------------------------------------ */ /** * @return The total number of threads currently in the pool */ @ManagedAttribute("number of threads in pool") public int getThreads(); - /* ------------------------------------------------------------ */ /** * @return The number of idle threads in the pool */ @ManagedAttribute("number of idle threads in pool") public int getIdleThreads(); - - /* ------------------------------------------------------------ */ + /** * @return True if the pool is low on threads */ @ManagedAttribute("indicates the pool is low on available threads") public boolean isLowOnThreads(); - - /* ------------------------------------------------------------ */ - /* ------------------------------------------------------------ */ + /** + *Specialized sub-interface of ThreadPool that allows to get/set + * the minimum and maximum number of threads of the pool.
+ */ public interface SizedThreadPool extends ThreadPool { + /** + * @return the minimum number of threads + */ int getMinThreads(); + + /** + * @return the maximum number of threads + */ int getMaxThreads(); + + /** + * @param threads the minimum number of threads + */ void setMinThreads(int threads); + + /** + * @param threads the maximum number of threads + */ void setMaxThreads(int threads); + + /** + * @return a ThreadPoolBudget for this sized thread pool, + * or null of no ThreadPoolBudget can be returned + */ default ThreadPoolBudget getThreadPoolBudget() { return null; diff --git a/jetty-websocket/websocket-tests/src/main/java/org/eclipse/jetty/websocket/tests/LocalWebSocketConnection.java b/jetty-websocket/websocket-tests/src/main/java/org/eclipse/jetty/websocket/tests/LocalWebSocketConnection.java index 0f23afaf41a..854eaa105a2 100644 --- a/jetty-websocket/websocket-tests/src/main/java/org/eclipse/jetty/websocket/tests/LocalWebSocketConnection.java +++ b/jetty-websocket/websocket-tests/src/main/java/org/eclipse/jetty/websocket/tests/LocalWebSocketConnection.java @@ -25,7 +25,7 @@ import java.util.concurrent.Executor; import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; -import org.eclipse.jetty.util.thread.ExecutorThreadPool; +import org.eclipse.jetty.util.thread.ExecutorSizedThreadPool; import org.eclipse.jetty.websocket.api.BatchMode; import org.eclipse.jetty.websocket.api.FrameCallback; import org.eclipse.jetty.websocket.api.SuspendToken; @@ -57,7 +57,7 @@ public class LocalWebSocketConnection implements LogicalConnection { this.id = id; this.bufferPool = bufferPool; - this.executor = new ExecutorThreadPool(); + this.executor = new ExecutorSizedThreadPool(); this.policy = WebSocketPolicy.newServerPolicy(); }