-
- All Superinterfaces:
- Executor, ExecutorService, ManagedExecutorService, ScheduledExecutorService
public interface ManagedScheduledExecutorService extends ManagedExecutorService, ScheduledExecutorService
A manageable version of aScheduledExecutorService
.A ManagedScheduledExecutorService extends the Java™ SE ScheduledExecutorService to provide methods for submitting delayed or periodic tasks for execution in a Java™ EE environment. Implementations of the ManagedScheduledExecutorService are provided by a Java™ EE Product Provider. Application Component Providers use the Java Naming and Directory Interface™ (JNDI) to look-up instances of one or more ManagedScheduledExecutorService objects using resource environment references. ManagedScheduledExecutorService instances can also be injected into application components through the use of the
Resource
annotation.The Concurrency Utilities for Java™ EE specification describes several behaviors that a ManagedScheduledExecutorService can implement. The Application Component Provider and Deployer identify these requirements and map the resource environment reference appropriately.
Tasks are run in managed threads provided by the Java™ EE Product Provider and are run within the application component context that submitted the task. All tasks run without an explicit transaction (they do not enlist in the application component's transaction). If a transaction is required, use a
javax.transaction.UserTransaction
instance. A UserTransaction instance is available in JNDI using the name: "java:comp/UserTransaction" or by requesting an injection of aUserTransaction
object using theResource
annotation.Example:
public run() { // Begin of task InitialContext ctx = new InitialContext(); UserTransaction ut = (UserTransaction) ctx.lookup("java:comp/UserTransaction"); ut.begin(); // Perform transactional business logic ut.commit(); }
Tasks can optionally provide anManagedTaskListener
to receive notifications of lifecycle events, through the use ofManagedTask
interface.Asynchronous tasks are typically submitted to the ManagedScheduledExecutorService using one of the
submit
orschedule
methods, each of which return aFuture
instance. The Future represents the result of the task and can also be used to check if the task is complete or wait for its completion.If the task is cancelled, the result for the task is a
CancellationException
exception. If the task is unable to run due to start due to a reason other than cancellation, the result is aAbortedException
exception. If the task is scheduled with aTrigger
and the Trigger forces the task to be skipped, the result will be aSkippedException
exception.Tasks can be scheduled to run periodically using the
schedule
methods that take aTrigger
as an argument and thescheduleAtFixedRate
andscheduleWithFixedDelay
methods. The result of theFuture
will be represented by the currently scheduled or running instance of the task. Future and past executions of the task are not represented by the Future. The state of theFuture
will therefore change and multiple results are expected.For example, if a task is repeating, the lifecycle of the task would be:
(Note: SeeManagedTaskListener
for task lifecycle management details.)Sequence State Action Listener Next state 1A. None submit() taskSubmitted Submitted 2A. Submitted About to call run() taskStarting Started 3A. Started Exit run() taskDone Reschedule 1B. Reschedule taskSubmitted Submitted 2B. Submitted About to call run() taskStarting Started 3B. Started Exit run() taskDone Reschedule - Since:
- 1.0
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method and Description <V> ScheduledFuture<V>
schedule(Callable<V> callable, Trigger trigger)
Creates and executes a task based on a Trigger.ScheduledFuture<?>
schedule(Runnable command, Trigger trigger)
Creates and executes a task based on a Trigger.-
Methods inherited from interface java.util.concurrent.ScheduledExecutorService
schedule, schedule, scheduleAtFixedRate, scheduleWithFixedDelay
-
Methods inherited from interface java.util.concurrent.ExecutorService
awaitTermination, invokeAll, invokeAll, invokeAny, invokeAny, isShutdown, isTerminated, shutdown, shutdownNow, submit, submit, submit
-
Methods inherited from interface java.util.concurrent.Executor
execute
-
-
-
-
Method Detail
-
schedule
ScheduledFuture<?> schedule(Runnable command, Trigger trigger)
Creates and executes a task based on a Trigger. The Trigger determines when the task should run and how often.- Parameters:
command
- the task to execute.trigger
- the trigger that determines when the task should fire.- Returns:
- a Future representing pending completion of the task, and whose
get()
method will returnnull
upon completion. - Throws:
RejectedExecutionException
- if task cannot be scheduled for execution.NullPointerException
- if command is null.
-
schedule
<V> ScheduledFuture<V> schedule(Callable<V> callable, Trigger trigger)
Creates and executes a task based on a Trigger. The Trigger determines when the task should run and how often.- Parameters:
callable
- the function to execute.trigger
- the trigger that determines when the task should fire.- Returns:
- a ScheduledFuture that can be used to extract result or cancel.
- Throws:
RejectedExecutionException
- if task cannot be scheduled for execution.NullPointerException
- if callable is null.
-
-
Traduction non disponible
Les API Java ne sont pas encore traduites en français sur l'infobrol. Seule la version anglaise est disponible pour l'instant.
Version en cache
21/08/2025 23:09:10 Cette version de la page est en cache (à la date du 21/08/2025 23:09:10) afin d'accélérer le traitement.Vous pouvez activer le mode utilisateur dans le menu en haut pour afficher la version plus récente de la page.
Document créé le 11/06/2005, dernière modification le 18/08/2025
Source du document imprimé : https://www.gaudry.be/java-api-javaee-rf-javax/enterprise/concurrent/managedscheduledexecutorservice.html
L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.
Références
Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.