public interface ManagedScheduledExecutorService extends ManagedExecutorService, ScheduledExecutorServiceSE
ScheduledExecutorService
SE の管理可能なバージョン。ManagedScheduledExecutorService は Java™ を継承します。SE ScheduledExecutorService は、Jakarta™ EE 環境で実行するために遅延タスクまたは定期タスクを送信するためのメソッドを提供します。ManagedScheduledExecutorService の実装は、Jakarta EE Product Provider によって提供されます。アプリケーションコンポーネントプロバイダーは、Java Naming and Directory Interface™ を使用します。(JNDI)リソース環境参照を使用して 1 つ以上の ManagedScheduledExecutorService オブジェクトのインスタンスを検索します。ManagedScheduledExecutorService インスタンスは、Resource
アノテーションを使用してアプリケーションコンポーネントに挿入することもできます。
Jakarta Concurrency 仕様には、ManagedScheduledExecutorService が実装できるいくつかの動作が記述されています。アプリケーションコンポーネントプロバイダーとデプロイヤーは、これらの要件を特定し、リソース環境参照を適切にマッピングします。
タスクは、Jakarta™ EE Product Provider によって提供されるマネージスレッドで実行され、タスクを送信したアプリケーションコンポーネントコンテキスト内で実行されます。すべてのタスクは、明示的なトランザクションなしで実行されます(アプリケーションコンポーネントのトランザクションに参加しません)。トランザクションが必要な場合は、javax.transaction.UserTransaction
インスタンスを使用してください。UserTransaction インスタンスは、名前 " java:comp/UserTransaction" を使用するか、Resource
アノテーションを使用して UserTransaction
オブジェクトの注入をリクエストすることにより、JNDI で使用できます。
例:
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 an
ManagedTaskListener
to receive
notifications of lifecycle events, through the use of ManagedTask
interface.
Asynchronous tasks are typically submitted to the ManagedScheduledExecutorService using one
of the submit
or schedule
methods, each of which return a Future
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 a
AbortedException
exception. If the task is scheduled
with a Trigger
and the Trigger forces the task to be skipped,
the result will be a SkippedException
exception.
Tasks can be scheduled to run periodically using the schedule
methods that
take a Trigger
as an argument and the scheduleAtFixedRate
and
scheduleWithFixedDelay
methods. The result of the Future
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 the Future
will therefore change
and multiple results are expected.
For example, if a task is repeating, the lifecycle of the task would be:
(Note: See ManagedTaskListener
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 |
Modifier and Type | Method and Description |
---|---|
<V> ScheduledFutureSE<V> |
schedule(CallableSE<V> callable,
Trigger trigger)
Creates and executes a task based on a Trigger.
|
ScheduledFutureSE<?> |
schedule(RunnableSE command,
Trigger trigger)
Creates and executes a task based on a Trigger.
|
scheduleSE, scheduleSE, scheduleAtFixedRateSE, scheduleWithFixedDelaySE
awaitTerminationSE, invokeAllSE, invokeAllSE, invokeAnySE, invokeAnySE, isShutdownSE, isTerminatedSE, shutdownSE, shutdownNowSE, submitSE, submitSE, submitSE
executeSE
ScheduledFutureSE<?> schedule(RunnableSE command, Trigger trigger)
command
- 実行するタスク。trigger
- タスクをいつ起動するかを決定するトリガー。get()
メソッドは完了時に null
を返します。RejectedExecutionExceptionSE
- タスクの実行をスケジュールできない場合。NullPointerExceptionSE
- コマンドが null の場合。<V> ScheduledFutureSE<V> schedule(CallableSE<V> callable, Trigger trigger)
callable
- 実行する関数。trigger
- タスクをいつ起動するかを決定するトリガー。RejectedExecutionExceptionSE
- タスクの実行をスケジュールできない場合。NullPointerExceptionSE
- callable が null の場合。Copyright © 2019 Eclipse Foundation.
Use is subject to license terms.