org.deegree.commons.concurrent
Class Executor

java.lang.Object
  extended by org.deegree.commons.concurrent.Executor

public class Executor
extends Object

The Executor is deegree's central place to:

The Executor class is realized as a singleton and uses a cached thread pool internally to minimize overhead for acquiring the necessary Thread instances and to manage the number of concurrent threads.

Version:
$Revision: 9339 $, $Date: 2007-12-27 12:31:52 +0000 (Do, 27 Dez 2007) $
Author:
Andreas Poth, Andreas Schmitz, Rutger Bezema, Markus Schneider, last edited by: $Author: apoth $
See Also:
ExecutorService, ExecutionFinishedListener

Method Summary
static Executor getInstance()
          Returns the only instance of this class (singleton pattern).
<T> void
performAsynchronously(Callable<T> task, ExecutionFinishedListener<T> finishedListener)
          Performs a task asynchronously (in an independent thread) without any time limit.
<T> void
performAsynchronously(Callable<T> task, ExecutionFinishedListener<T> finishedListener, long timeout)
          Performs a task asynchronously (in an independent thread) with a given time limit.
<T> T
performSynchronously(Callable<T> task, long timeout)
          Performs a task synchronously with a given timeout.
<T> List<ExecutionFinishedEvent<T>>
performSynchronously(List<Callable<T>> tasks)
          Performs several tasks synchronously in parallel threads.
<T> List<ExecutionFinishedEvent<T>>
performSynchronously(List<Callable<T>> tasks, long timeout)
          Performs several tasks synchronously with a given timeout in parallel threads.
 void shutdown()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static Executor getInstance()
Returns the only instance of this class (singleton pattern).

Returns:
the only instance of this class

performAsynchronously

public <T> void performAsynchronously(Callable<T> task,
                                      ExecutionFinishedListener<T> finishedListener)
Performs a task asynchronously (in an independent thread) without any time limit.

Type Parameters:
T - type of return value
Parameters:
task - task to be performed (specified in the Callable.call() method)
finishedListener - notified when the method call finishes (succesfully or abnormally), may be null

performAsynchronously

public <T> void performAsynchronously(Callable<T> task,
                                      ExecutionFinishedListener<T> finishedListener,
                                      long timeout)
Performs a task asynchronously (in an independent thread) with a given time limit.

Type Parameters:
T - type of return value
Parameters:
task - task to be performed (specified in the Callable.call() method)
finishedListener - notified when the method call finishes (succesfully or abnormally), may be null
timeout - maximum time allowed for execution in milliseconds

performSynchronously

public <T> T performSynchronously(Callable<T> task,
                                  long timeout)
                       throws CancellationException,
                              InterruptedException,
                              Throwable
Performs a task synchronously with a given timeout.

Type Parameters:
T - type of return value
Parameters:
task - tasks to be performed (specified in the Callable.call() method)
timeout - maximum time allowed for execution in milliseconds
Returns:
result value of the called method
Throws:
CancellationException - if the execution time exceeds the specified timeout / thread has been cancelled
InterruptedException - if interrupted while waiting, in which case unfinished tasks are cancelled
Throwable - if the tasks throws an exception itself

performSynchronously

public <T> List<ExecutionFinishedEvent<T>> performSynchronously(List<Callable<T>> tasks)
                                                     throws InterruptedException
Performs several tasks synchronously in parallel threads.

This method does not return before all tasks are finished (successfully or abnormally). For each given Callable, an independent thread is used. For each task, an ExecutionFinishedEvent is generated and returned.

Type Parameters:
T - the result type of the callables
Parameters:
tasks - tasks to be performed (specified in the Callable.call() methods)
Returns:
ExecutionFinishedEvents for all tasks
Throws:
InterruptedException - if the current thread was interrupted while waiting

performSynchronously

public <T> List<ExecutionFinishedEvent<T>> performSynchronously(List<Callable<T>> tasks,
                                                                long timeout)
                                                     throws InterruptedException
Performs several tasks synchronously with a given timeout in parallel threads.

This method does not return before all tasks are finished (successfully or abnormally). For each given Callable, an independent thread is used. For each task, an ExecutionFinishedEvent is generated and returned.

Type Parameters:
T - the result type of the tasks
Parameters:
tasks - tasks to be performed (specified in the Callable.call() methods)
timeout - maximum time allowed for execution (in milliseconds)
Returns:
ExecutionFinishedEvents for all tasks
Throws:
InterruptedException - if the current thread was interrupted while waiting

shutdown

public void shutdown()


Copyright © 2011. All Rights Reserved.