com.levigo.util.concurrent.tasks
Class ThreadPoolTaskService

java.lang.Object
  extended by com.levigo.util.concurrent.tasks.ThreadPoolTaskService
All Implemented Interfaces:
TaskService

public class ThreadPoolTaskService
extends Object
implements TaskService

A TaskService implementation which makes use of a ThreadPoolExecutor to execute tasks on a number of background threads.


Constructor Summary
ThreadPoolTaskService(String name)
           
 
Method Summary
 void addTaskListener(TaskListener l)
          Add a listener to receive notifications about the activities of this task service.
 int getActiveTaskCount()
           
 int getCorePoolSize()
           
static ThreadPoolTaskService getDefault()
           
 TaskExecutor<Object> getExecutor()
          Get a TaskExecutor scoped for the current thread.
<R> TaskExecutor<R>
getExecutor(TaskScope<R> scope)
          Create a TaskExecutor for the given TaskScope.
<R> TaskExecutor<R>
getExecutor(TaskScope<R> scope, int priority)
          Create a TaskExecutor for the given TaskScope.
 int getMaximumPoolSize()
           
 int getQueuedTaskCount()
           
 void removeTaskListener(TaskListener l)
          Remove a listener previously installed to receive notifications about the activities of this task service.
 void setCorePoolSize(int corePoolSize)
           
static void setExecutorManager(ExecutorManager executorManager)
           
 void setMaximumPoolSize(int maximumPoolSize)
           
 void shutdown()
           
static void shutdownDefault()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ThreadPoolTaskService

public ThreadPoolTaskService(String name)
Method Detail

getDefault

public static ThreadPoolTaskService getDefault()

setExecutorManager

public static void setExecutorManager(ExecutorManager executorManager)

shutdownDefault

public static void shutdownDefault()

addTaskListener

public void addTaskListener(TaskListener l)
Description copied from interface: TaskService
Add a listener to receive notifications about the activities of this task service.

Specified by:
addTaskListener in interface TaskService
Parameters:
l - the listener

getActiveTaskCount

public int getActiveTaskCount()

getCorePoolSize

public int getCorePoolSize()
See Also:
ThreadPoolExecutor.getCorePoolSize()

getExecutor

public TaskExecutor<Object> getExecutor()
Get a TaskExecutor scoped for the current thread. If no scope for the current thread exists, a new scope is created. The scope inherits the current thread's priority.

Specified by:
getExecutor in interface TaskService
Returns:
an executor with an unconstrained result type.

getExecutor

public <R> TaskExecutor<R> getExecutor(TaskScope<R> scope)
Description copied from interface: TaskService
Create a TaskExecutor for the given TaskScope. Tasks will be executed with the default priority.

Specified by:
getExecutor in interface TaskService
Returns:
an executor with the given result type.

getExecutor

public <R> TaskExecutor<R> getExecutor(TaskScope<R> scope,
                                       int priority)
Description copied from interface: TaskService
Create a TaskExecutor for the given TaskScope. Tasks will be executed with the given priority.

Specified by:
getExecutor in interface TaskService
Returns:
an executor with the given result type.

getMaximumPoolSize

public int getMaximumPoolSize()
See Also:
ThreadPoolExecutor.getMaximumPoolSize()

getQueuedTaskCount

public int getQueuedTaskCount()

removeTaskListener

public void removeTaskListener(TaskListener l)
Description copied from interface: TaskService
Remove a listener previously installed to receive notifications about the activities of this task service.

Specified by:
removeTaskListener in interface TaskService
Parameters:
l - the listener

setCorePoolSize

public void setCorePoolSize(int corePoolSize)
Parameters:
corePoolSize -
See Also:
ThreadPoolExecutor.setCorePoolSize(int)

setMaximumPoolSize

public void setMaximumPoolSize(int maximumPoolSize)
Parameters:
maximumPoolSize -
See Also:
ThreadPoolExecutor.setMaximumPoolSize(int)

shutdown

public void shutdown()


Copyright © 1995-2020 levigo holding gmbh. All Rights Reserved.