org.apache.felix.httplite.server
Class ThreadPool

java.lang.Object
  extended by org.apache.felix.httplite.server.ThreadPool

public class ThreadPool
extends java.lang.Object

This class implements a simple thread pool for servicing HTTP connections. The thread pool does not create any threads initially, but waits for connections to be added to create threads. As connections are added, threads are only created if they are needed up until the thread limit. If threads are inactive for a period of time, then the threads terminate; the default is 60000 milliseconds.


Field Summary
static int DEFAULT_THREAD_TIMEOUT
          Default thread timeout
 
Constructor Summary
ThreadPool(int threadLimit, int threadTimeout, Logger logger)
          Constructs a thread pool with the specified thread limit and inactivity timeout.
ThreadPool(int threadLimit, Logger logger)
          Constructs a thread pool with the specified thread limit and with the default inactivity timeout.
 
Method Summary
 void addConnection(Connection connection)
          This method adds an HTTP connection to the thread pool for servicing.
 int getState()
          This method returns the current state of the thread pool, which is one of the following values: ThreadPool.INACTIVE_STATE - the thread pool is currently not active.
 void start()
          Starts the thread pool if it is not already active, allowing it to service connections.
 void stop()
          This method stops the thread pool if it is currently active.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_THREAD_TIMEOUT

public static final int DEFAULT_THREAD_TIMEOUT
Default thread timeout

See Also:
Constant Field Values
Constructor Detail

ThreadPool

public ThreadPool(int threadLimit,
                  Logger logger)
Constructs a thread pool with the specified thread limit and with the default inactivity timeout.

Parameters:
threadLimit - The maximum number of threads in the pool.
logger - Logger instance.

ThreadPool

public ThreadPool(int threadLimit,
                  int threadTimeout,
                  Logger logger)
Constructs a thread pool with the specified thread limit and inactivity timeout.

Parameters:
threadLimit - The maximum number of threads in the pool.
threadTimeout - The inactivity timeout for threads in milliseconds.
logger - Logger instance.
Method Detail

getState

public int getState()
This method returns the current state of the thread pool, which is one of the following values:

start

public void start()
Starts the thread pool if it is not already active, allowing it to service connections.

Throws:
java.lang.IllegalStateException - If the thread pool is in the ThreadPool.STOPPING_STATE state.

stop

public void stop()
          throws java.lang.InterruptedException
This method stops the thread pool if it is currently active. This method will block the calling thread until the thread pool is completely stopped. This can potentially take a long time, since it allows all existing connections to be processed before shutting down. Subsequent calls to this method will also block the caller. If a blocked thread is interrupted, the method will release the blocked thread by throwing an interrupted exception. In such a case, the thread pool will still continue its shutdown process.

Throws:
java.lang.InterruptedException - If the calling thread is interrupted.

addConnection

public void addConnection(Connection connection)
This method adds an HTTP connection to the thread pool for servicing.

Parameters:
connection -
Throws:
java.lang.IllegalStateException - If the thread pool is not in the ThreadPool.ACTIVE_STATE state.


Copyright © 2006-2012 The Apache Software Foundation. All Rights Reserved.