Package de.xima.fc.gui.common.listener
Class TaskExecutorListener
- java.lang.Object
-
- de.xima.fc.gui.common.listener.TaskExecutorListener
-
- All Implemented Interfaces:
EventListener
,javax.servlet.ServletContextListener
public class TaskExecutorListener extends Object implements javax.servlet.ServletContextListener
- Author:
- XIMA MEDIA GmbH
-
-
Constructor Summary
Constructors Constructor Description TaskExecutorListener()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
contextDestroyed(javax.servlet.ServletContextEvent cs)
void
contextInitialized(javax.servlet.ServletContextEvent cs)
static <T> ScheduledFuture<?>
scheduleTask(Runnable runnable, long delay, TimeUnit unit)
Creates and executes a one-shot action that becomes enabled after the given delay.static <T> ScheduledFuture<T>
scheduleTask(Callable<T> callable, long delay, TimeUnit unit)
Creates and executes a ScheduledFuture that becomes enabled after the given delay.static Future<?>
submitTask(Runnable runnable)
Submits a Runnable task for execution and returns a Future representing that task.static <T> Future<T>
submitTask(Callable<T> callable)
Submits a value-returning task for execution and returns a Future representing the pending results of the task.
-
-
-
Method Detail
-
contextInitialized
public void contextInitialized(javax.servlet.ServletContextEvent cs)
- Specified by:
contextInitialized
in interfacejavax.servlet.ServletContextListener
-
contextDestroyed
public void contextDestroyed(javax.servlet.ServletContextEvent cs)
- Specified by:
contextDestroyed
in interfacejavax.servlet.ServletContextListener
-
submitTask
public static Future<?> submitTask(Runnable runnable)
Submits a Runnable task for execution and returns a Future representing that task. The Future'sget
method will returnnull
upon successful completion.- Parameters:
runnable
- the task to submit- Returns:
- a Future representing pending completion of the task
- Throws:
RejectedExecutionException
- if the task cannot be scheduled for executionNullPointerException
- if the task is null
-
scheduleTask
public static <T> ScheduledFuture<?> scheduleTask(Runnable runnable, long delay, TimeUnit unit)
Creates and executes a one-shot action that becomes enabled after the given delay.- Parameters:
runnable
- the task to executedelay
- the time from now to delay executionunit
- the time unit of the delay parameter- Returns:
- a ScheduledFuture representing pending completion of the task and whose
get()
method will returnnull
upon completion - Throws:
RejectedExecutionException
- if the task cannot be scheduled for executionNullPointerException
- if command is null
-
scheduleTask
public static <T> ScheduledFuture<T> scheduleTask(Callable<T> callable, long delay, TimeUnit unit)
Creates and executes a ScheduledFuture that becomes enabled after the given delay.- Type Parameters:
T
- the type of the callable's result- Parameters:
callable
- the function to executedelay
- the time from now to delay executionunit
- the time unit of the delay parameter- Returns:
- a ScheduledFuture that can be used to extract result or cancel
- Throws:
RejectedExecutionException
- if the task cannot be scheduled for executionNullPointerException
- if callable is null
-
submitTask
public static <T> Future<T> submitTask(Callable<T> callable)
Submits a value-returning task for execution and returns a Future representing the pending results of the task. The Future'sget
method will return the task's result upon successful completion.If you would like to immediately block waiting for a task, you can use constructions of the form
result = exec.submit(aCallable).get();
Note: The
Executors
class includes a set of methods that can convert some other common closure-like objects, for example,PrivilegedAction
toCallable
form so they can be submitted.- Type Parameters:
T
- the type of the task's result- Parameters:
callable
- the task to submit- Returns:
- a Future representing pending completion of the task
- Throws:
RejectedExecutionException
- if the task cannot be scheduled for executionNullPointerException
- if the task is null
-
-