クラス ThreadPoolTaskExecutor
- 実装されたすべてのインターフェース:
SerializableSE
、ExecutorSE
、ThreadFactorySE
、Aware
、BeanNameAware
、DisposableBean
、InitializingBean
、AsyncListenableTaskExecutor
、AsyncTaskExecutor
、TaskExecutor
、SchedulingTaskExecutor
ThreadPoolExecutor
SE を構成し( "corePoolSize"、"maxPoolSize"、"keepAliveSeconds"、"queueCapacity" プロパティを使用して)、Spring TaskExecutor
として公開できる JavaBean。このクラスは、管理および監視(JMX など)にも適しています。いくつかの有用な属性を提供します。"corePoolSize"、"maxPoolSize"、"keepAliveSeconds" (実行時のすべての更新をサポート)。"poolSize"、"activeCount" (イントロスペクションのみ)。 デフォルトの構成はコアプールサイズ 1 で、最大プールサイズとキュー容量は無制限です。これは、すべてのタスクで単一のスレッドを共有する Executors.newSingleThreadExecutor()
とほぼ同等です。"queueCapacity"
を 0 に設定すると、Executors.newCachedThreadPool()
を模倣し、プール内のスレッドを潜在的に非常に高い数に即座にスケーリングします。また、その時点で "maxPoolSize"
を設定し、場合によってはより高い "corePoolSize"
を設定することも検討してください(スケーリングの "allowCoreThreadTimeOut"
モードも参照してください)。
注意 : このクラスは、Spring の TaskExecutor
インターフェースと Executor
SE インターフェースを実装します。前者はプライマリインターフェースであり、もう一方は単に二次的な利便性として機能します。このため、例外処理は、特に TaskRejectedException
に関して、Executor 契約ではなく TaskExecutor 契約に従います。
別の方法として、コンストラクターインジェクションを使用して ThreadPoolExecutor インスタンスを直接セットアップするか、Executors
SE クラスを指すファクトリメソッド定義を使用することができます。このような生のエグゼキュータを Spring TaskExecutor
として公開するには、単に ConcurrentTaskExecutor
アダプターでラップします。
- 導入:
- 2.0
- 作成者:
- Juergen Hoeller, R é my Guihard, Sam Brannen
- 関連事項:
フィールドサマリー
クラス org.springframework.scheduling.concurrent.ExecutorConfigurationSupport から継承されたフィールド
logger
インターフェース org.springframework.core.task.AsyncTaskExecutor から継承されたフィールド
TIMEOUT_IMMEDIATE, TIMEOUT_INDEFINITE
コンストラクターのサマリー
コンストラクターメソッドのサマリー
修飾子と型メソッド説明protected void
ExecutorService.shutdownNow()
から返された、実行を決して推奨しない残りのタスクをキャンセルします。protected BlockingQueueSE<RunnableSE>
createQueue
(int queueCapacity) BlockingQueue を作成して、ThreadPoolExecutor に使用します。void
execute
(RunnableSE task) 指定されたtask
を実行します。void
execute
(RunnableSE task, long startTimeout) 使用すべきではありません。int
現在アクティブなスレッドの数を返します。int
ThreadPoolExecutor のコアプールサイズを返します。int
ThreadPoolExecutor のキープアライブ秒数を返します。int
ThreadPoolExecutor の最大プールサイズを返します。int
現在のプールサイズを返します。int
ThreadPoolExecutor の BlockingQueue の容量を返します。int
現在のキューサイズを返します。ネイティブアクセスの基になる ThreadPoolExecutor を返します。protected ExecutorServiceSE
initializeExecutor
(ThreadFactorySE threadFactory, RejectedExecutionHandlerSE rejectedExecutionHandler) メモ: このメソッドは、ExecutorService
SE をその基本クラスに公開しますが、実際のThreadPoolExecutor
SE ハンドルを内部に保存します。void
setAllowCoreThreadTimeOut
(boolean allowCoreThreadTimeOut) コアスレッドのタイムアウトを許可するかどうかを指定します。void
setCorePoolSize
(int corePoolSize) ThreadPoolExecutor のコアプールサイズを設定します。void
setKeepAliveSeconds
(int keepAliveSeconds) ThreadPoolExecutor のキープアライブ秒数を設定します。void
setMaxPoolSize
(int maxPoolSize) ThreadPoolExecutor の最大プールサイズを設定します。void
setPrestartAllCoreThreads
(boolean prestartAllCoreThreads) すべてのコアスレッドを開始して、アイドル状態で作業を待機させるかどうかを指定します。void
setQueueCapacity
(int queueCapacity) ThreadPoolExecutor の BlockingQueue の容量を設定します。void
setTaskDecorator
(TaskDecorator taskDecorator) 実行しようとしているRunnable
SE に適用するカスタムTaskDecorator
を指定します。FutureSE<?>
submit
(RunnableSE task) 実行可能な Runnable タスクを送信し、そのタスクを表す Future を受け取ります。<T> FutureSE<T>
submit
(CallableSE<T> task) Callable タスクを送信して実行し、そのタスクを表す Future を受け取ります。submitListenable
(RunnableSE task) Runnable
タスクを実行のために送信し、そのタスクを表すListenableFuture
を受け取ります。<T> ListenableFuture<T>
submitListenable
(CallableSE<T> task) Callable
タスクを実行のために送信し、そのタスクを表すListenableFuture
を受け取ります。クラス org.springframework.scheduling.concurrent.ExecutorConfigurationSupport から継承されたメソッド
afterPropertiesSet, destroy, initialize, setAwaitTerminationMillis, setAwaitTerminationSeconds, setBeanName, setRejectedExecutionHandler, setThreadFactory, setThreadNamePrefix, setWaitForTasksToCompleteOnShutdown, shutdown
クラス org.springframework.scheduling.concurrent.CustomizableThreadFactory から継承されたメソッド
newThread
クラス org.springframework.util.CustomizableThreadCreator から継承されたメソッド
createThread, getDefaultThreadNamePrefix, getThreadGroup, getThreadNamePrefix, getThreadPriority, isDaemon, nextThreadName, setDaemon, setThreadGroup, setThreadGroupName, setThreadPriority
クラス java.lang.ObjectSE から継承されたメソッド
clone, equalsSE, finalize, getClass, hashCode, notify, notifyAll, toString, wait, waitSE, waitSE
インターフェース org.springframework.core.task.AsyncTaskExecutor から継承されたメソッド
submitCompletable, submitCompletable
インターフェース org.springframework.scheduling.SchedulingTaskExecutor から継承されたメソッド
prefersShortLivedTasks
コンストラクターの詳細
ThreadPoolTaskExecutor
public ThreadPoolTaskExecutor()
メソッドの詳細
setCorePoolSize
public void setCorePoolSize(int corePoolSize) ThreadPoolExecutor のコアプールサイズを設定します。デフォルトは 1 です。この設定は、JMX などを介して実行時に変更できます。
getCorePoolSize
public int getCorePoolSize()ThreadPoolExecutor のコアプールサイズを返します。setMaxPoolSize
public void setMaxPoolSize(int maxPoolSize) ThreadPoolExecutor の最大プールサイズを設定します。デフォルトはInteger.MAX_VALUE
です。この設定は、JMX などを介して実行時に変更できます。
getMaxPoolSize
public int getMaxPoolSize()ThreadPoolExecutor の最大プールサイズを返します。setKeepAliveSeconds
public void setKeepAliveSeconds(int keepAliveSeconds) ThreadPoolExecutor のキープアライブ秒数を設定します。デフォルトは 60 です。
この設定は、JMX などを介して実行時に変更できます。
getKeepAliveSeconds
public int getKeepAliveSeconds()ThreadPoolExecutor のキープアライブ秒数を返します。setQueueCapacity
public void setQueueCapacity(int queueCapacity) ThreadPoolExecutor の BlockingQueue の容量を設定します。デフォルトは
Integer.MAX_VALUE
です。正の値は、LinkedBlockingQueue インスタンスにつながります。その他の値は、SynchronousQueue インスタンスにつながります。
getQueueCapacity
public int getQueueCapacity()ThreadPoolExecutor の BlockingQueue の容量を返します。- 導入:
- 5.3.21
- 関連事項:
setAllowCoreThreadTimeOut
public void setAllowCoreThreadTimeOut(boolean allowCoreThreadTimeOut) コアスレッドのタイムアウトを許可するかどうかを指定します。これにより、ゼロ以外のキューと組み合わせても動的な拡大と縮小が可能になります(最大プールサイズはキューがいっぱいになると拡大するため)。デフォルトは「false」。
setPrestartAllCoreThreads
public void setPrestartAllCoreThreads(boolean prestartAllCoreThreads) すべてのコアスレッドを開始して、アイドル状態で作業を待機させるかどうかを指定します。デフォルトは「false」。
- 導入:
- 5.3.14
- 関連事項:
setTaskDecorator
実行しようとしているRunnable
SE に適用するカスタムTaskDecorator
を指定します。このようなデコレータは、必ずしもユーザー提供の
Runnable
/Callable
に適用されるのではなく、実際の実行コールバック(ユーザー提供のタスクのラッパーである可能性があります)に適用されることに注意してください。主な使用例は、タスクの呼び出しの周囲に実行コンテキストを設定するか、タスク実行の監視 / 統計を提供することです。
注意 :
TaskDecorator
実装での例外処理は、execute
呼び出しによる単純なRunnable
実行に制限されています。#submit
呼び出しの場合、公開されたRunnable
は、例外を伝搬しないFutureTask
になります。例外を評価するには、キャストしてFuture#get
を呼び出す必要がある場合があります。このようなFuture
ケースで例外にアクセスする方法の例については、ThreadPoolExecutor#afterExecute
javadoc を参照してください。- 導入:
- 4.3
initializeExecutor
protected ExecutorServiceSE initializeExecutor(ThreadFactorySE threadFactory, RejectedExecutionHandlerSE rejectedExecutionHandler) メモ: このメソッドは、ExecutorService
SE をその基本クラスに公開しますが、実際のThreadPoolExecutor
SE ハンドルを内部に保存します。このメソッドをオーバーライドして、executor を置き換えるのではなく、単にExecutorService
ハンドルを装飾したり、カスタム状態を保管したりしてください。- 次で指定:
- クラス
ExecutorConfigurationSupport
のinitializeExecutor
- パラメーター:
threadFactory
- 使用する ThreadFactoryrejectedExecutionHandler
- 使用する RejectedExecutionHandler- 戻り値:
- 新しい ExecutorService インスタンス
- 関連事項:
createQueue
BlockingQueue を作成して、ThreadPoolExecutor に使用します。正の容量値に対して LinkedBlockingQueue インスタンスが作成されます。SynchronousQueue その他。
- パラメーター:
queueCapacity
- 指定されたキュー容量- 戻り値:
- BlockingQueue インスタンス
- 関連事項:
getThreadPoolExecutor
ネイティブアクセスの基になる ThreadPoolExecutor を返します。- 戻り値:
- 基になる ThreadPoolExecutor (非
null
) - 例外:
IllegalStateExceptionSE
- ThreadPoolTaskExecutor がまだ初期化されていない場合
getPoolSize
public int getPoolSize()現在のプールサイズを返します。getQueueSize
public int getQueueSize()現在のキューサイズを返します。- 導入:
- 5.3.21
- 関連事項:
getActiveCount
public int getActiveCount()現在アクティブなスレッドの数を返します。execute
インターフェースからコピーされた説明:TaskExecutor
指定されたtask
を実行します。実装が非同期実行戦略を使用している場合、呼び出しはすぐに戻るか、同期実行の場合はブロックする可能性があります。
- 次で指定:
- インターフェース
ExecutorSE
のexecuteSE
- 次で指定:
- インターフェース
TaskExecutor
のexecute
- パラメーター:
task
- 実行するRunnable
(非null
)
execute
使用すべきではありません。インターフェースからコピーされた説明:AsyncTaskExecutor
指定されたtask
を実行します。- 次で指定:
- インターフェース
AsyncTaskExecutor
のexecute
- パラメーター:
task
- 実行するRunnable
(非null
)startTimeout
- タスクが開始される予定の期間(ミリ秒)。これはエグゼキューターへのヒントとして意図されており、即時タスクの優先処理を可能にします。一般的な値はAsyncTaskExecutor.TIMEOUT_IMMEDIATE
またはAsyncTaskExecutor.TIMEOUT_INDEFINITE
(TaskExecutor.execute(Runnable)
で使用されるデフォルト)です。- 関連事項:
submit
インターフェースからコピーされた説明:AsyncTaskExecutor
実行可能な Runnable タスクを送信し、そのタスクを表す Future を受け取ります。Future は完了時にnull
の結果を返します。- 次で指定:
- インターフェース
AsyncTaskExecutor
のsubmit
- パラメーター:
task
- 実行するRunnable
(非null
)- 戻り値:
- タスクの保留中の補完を表す Future
submit
インターフェースからコピーされた説明:AsyncTaskExecutor
Callable タスクを送信して実行し、そのタスクを表す Future を受け取ります。Future は、完了時に Callable の結果を返します。- 次で指定:
- インターフェース
AsyncTaskExecutor
のsubmit
- パラメーター:
task
- 実行するCallable
(非null
)- 戻り値:
- タスクの保留中の補完を表す Future
submitListenable
インターフェースからコピーされた説明:AsyncListenableTaskExecutor
Runnable
タスクを実行のために送信し、そのタスクを表すListenableFuture
を受け取ります。Future は完了時にnull
の結果を返します。- 次で指定:
- インターフェース
AsyncListenableTaskExecutor
のsubmitListenable
- パラメーター:
task
- 実行するRunnable
(非null
)- 戻り値:
- 保留中のタスクの補完を表す
ListenableFuture
submitListenable
インターフェースからコピーされた説明:AsyncListenableTaskExecutor
Callable
タスクを実行のために送信し、そのタスクを表すListenableFuture
を受け取ります。Future は、完了時に Callable の結果を返します。- 次で指定:
- インターフェース
AsyncListenableTaskExecutor
のsubmitListenable
- パラメーター:
task
- 実行するCallable
(非null
)- 戻り値:
- 保留中のタスクの補完を表す
ListenableFuture
cancelRemainingTask
クラスからコピーされた説明:ExecutorConfigurationSupport
ExecutorService.shutdownNow()
から返された、実行を決して推奨しない残りのタスクをキャンセルします。- オーバーライド:
- クラス
ExecutorConfigurationSupport
のcancelRemainingTask
- パラメーター:
task
- キャンセルするタスク (通常、RunnableFuture
SE )- 関連事項: