Class TaskExecutorListener

  • All Implemented Interfaces:
    EventListener, javax.servlet.ServletContextListener

    public class TaskExecutorListener
    extends Object
    implements javax.servlet.ServletContextListener
    Author:
    XIMA MEDIA GmbH
    • Constructor Detail

      • TaskExecutorListener

        public TaskExecutorListener()
    • Method Detail

      • contextInitialized

        public void contextInitialized​(javax.servlet.ServletContextEvent cs)
        Specified by:
        contextInitialized in interface javax.servlet.ServletContextListener
      • contextDestroyed

        public void contextDestroyed​(javax.servlet.ServletContextEvent cs)
        Specified by:
        contextDestroyed in interface javax.servlet.ServletContextListener
      • submitTask

        public static Future<?> submitTask​(Runnable runnable)
        Submits a Runnable task for execution and returns a Future representing that task. The Future's get method will return null 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 execution
        NullPointerException - 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 execute
        delay - the time from now to delay execution
        unit - the time unit of the delay parameter
        Returns:
        a ScheduledFuture representing pending completion of the task and whose get() method will return null upon completion
        Throws:
        RejectedExecutionException - if the task cannot be scheduled for execution
        NullPointerException - 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 execute
        delay - the time from now to delay execution
        unit - 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 execution
        NullPointerException - 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's get 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 to Callable 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 execution
        NullPointerException - if the task is null