com.continuent.tungsten.common.concurrent
Class SimpleJobService<V>

java.lang.Object
  extended by com.continuent.tungsten.common.concurrent.SimpleJobService<V>

public class SimpleJobService<V>
extends java.lang.Object

This class implements a wrapper around the Java ExecutorService interface to present a simplified interface for spawning and managing tasks. Tasks submitted to the service return a particular type, which is used to parameterize this class.

Version:
1.0
Author:
Robert Hodges

Constructor Summary
SimpleJobService(java.lang.String name, int maxThreads, int maxRequests, int keepAlive)
          Creates the job service.
 
Method Summary
 int getActiveTaskCount()
          Returns the number of tasks that are currently executing.
 int getPendingTaskCount()
          Returns the number of tasks that are submitted and awaiting execution.
 void shutdown()
          Shut down the job service by letting current tasks run to completion but accepting no further tasks.
 void shutdownNow()
          Shut down the job service immediately.
 java.util.concurrent.Future<V> submit(java.util.concurrent.Callable<V> task)
          Submits a task for execution.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleJobService

public SimpleJobService(java.lang.String name,
                        int maxThreads,
                        int maxRequests,
                        int keepAlive)
Creates the job service.

Parameters:
name - Name of this service, which will be prefixed to threads
maxThreads - Maximum number of threads in the pool; must be at least 1
maxRequests - Maximum number of pending requests; must be at least 1
keepAlive - Number of seconds to retain unused threads
Method Detail

submit

public java.util.concurrent.Future<V> submit(java.util.concurrent.Callable<V> task)
                                      throws java.util.concurrent.RejectedExecutionException
Submits a task for execution.

Returns:
A Future that allows clients to fetch result of running task.
Throws:
java.util.concurrent.RejectedExecutionException - Thrown if the task cannot be submitted, typically because the request queue is full

getPendingTaskCount

public int getPendingTaskCount()
Returns the number of tasks that are submitted and awaiting execution. This number is approximate.


getActiveTaskCount

public int getActiveTaskCount()
Returns the number of tasks that are currently executing. This number is approximate.


shutdown

public void shutdown()
Shut down the job service by letting current tasks run to completion but accepting no further tasks.


shutdownNow

public void shutdownNow()
Shut down the job service immediately. This may leave tasks in odd states depending how well they clean up.