-
public interface ManagedTaskListener
A ManagedTaskListener is used to monitor the state of a task's Future. It can be registered with aManagedExecutorService
using thesubmit
methods and will be invoked when the state of theFuture
changes. Each listener method will run with unspecified context. All listeners run without an explicit transaction (they do not enlist in the application component's transaction). If a transaction is required, use aUserTransaction
instance.Each listener instance will be invoked within the same process in which the listener was registered. If a single listener is submitted to multiple ManagedExecutorService instances, the listener object may be invoked concurrently by multiple threads.
Each listener method supports a minimum quality of service of at-most-once. A listener is not guaranteed to be invoked due to a process failure or termination.
State Transition Diagram
The following state transition figure and tables describe the possible task lifecycle events that can occur when a ManagedTaskListener is associated with a task. Each method is invoked when the state of the
Future
moves from one state to another.A. The task runs normally:
Sequence State Action Listener Next state 1. None submit() taskSubmitted Submitted 2. Submitted About to call run() taskStarting Started 3. Started Exit run() taskDone Done B. The task is cancelled during taskSubmitted():
Sequence State Action Listener Next state 1. None submit() taskSubmitted
Future is cancelled.Cancelling 2. Cancelling taskAborted Cancelled 3. Cancelled taskDone Done C. The task is cancelled or aborted after submitted, but before started:
Sequence State Action Listener Next state 1. None submit() taskSubmitted Submitted 2. Submitted cancel() or abort taskAborted Cancelled 3. Cancelled taskDone Done D. The task is cancelled when it is starting:
Sequence State Action Listener Next state 1. None submit() taskSubmitted Submitted 2. Submitted About to call run() taskStarting
Future is cancelled.Cancelling 3. Cancelling taskAborted Cancelled 4. Cancelled taskDone Done - Since:
- 1.0
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method and Description void
taskAborted(Future<?> future, ManagedExecutorService executor, Object task, Throwable exception)
Called when a task's Future has been cancelled anytime during the life of a task.void
taskDone(Future<?> future, ManagedExecutorService executor, Object task, Throwable exception)
Called when a submitted task has completed running, either successfully or failed due to any exception thrown from the task, task being cancelled, rejected, or aborted.void
taskStarting(Future<?> future, ManagedExecutorService executor, Object task)
This method is called before the task is about to start.void
taskSubmitted(Future<?> future, ManagedExecutorService executor, Object task)
Called after the task has been submitted to the Executor.
-
-
-
Method Detail
-
taskSubmitted
void taskSubmitted(Future<?> future, ManagedExecutorService executor, Object task)
Called after the task has been submitted to the Executor. The task will not enter the starting state until the taskSubmitted listener has completed. This method may be called from the same thread that the task was submitted with.This event does not indicate that the task has been scheduled for execution.
- Parameters:
future
- theFuture
instance that was created when the task was submitted.executor
- the executor used to run the associated Future.task
- the task that was submitted.
-
taskAborted
void taskAborted(Future<?> future, ManagedExecutorService executor, Object task, Throwable exception)
Called when a task's Future has been cancelled anytime during the life of a task. This method may be called after taskDone(). TheFuture.isCancelled()
method returns false if the task was aborted through another means other thanFuture.cancel(boolean)
. The exception argument will represent the cause of the cancellation:CancellationException
if the task was cancelled,SkippedException
if the task was skipped orAbortedException
if the task failed to start for another reason.
AbortedException.getCause()
method will return the exception that caused the task to fail to start.- Parameters:
future
- theFuture
instance that was created when the task was submitted.executor
- the executor used to run the associated Future.task
- the task that was submitted.exception
- the cause of the task abort.
-
taskDone
void taskDone(Future<?> future, ManagedExecutorService executor, Object task, Throwable exception)
Called when a submitted task has completed running, either successfully or failed due to any exception thrown from the task, task being cancelled, rejected, or aborted.- Parameters:
future
- theFuture
instance that was created when the task was submitted.executor
- the executor used to run the associated Future.task
- the task that was submitted.exception
- if not null, the exception that caused the task to fail.
-
taskStarting
void taskStarting(Future<?> future, ManagedExecutorService executor, Object task)
This method is called before the task is about to start. The task will not enter the starting state until the taskSubmitted listener has completed. This method may be called from the same thread that the task was submitted with.- Parameters:
future
- theFuture
instance that was created when the task was submitted.executor
- the executor used to run the associated Future.task
- the task that was submitted.
-
-
Nederlandse vertaling
U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.
Bij voorbaat dank.
Document heeft de 11/06/2005 gemaakt, de laatste keer de 18/08/2025 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/java-api-javaee-rf-javax/enterprise/concurrent/ManagedTaskListener.html
De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.
Referenties
Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur van deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.