public class SystemCommandTasklet extends StepExecutionListenerSupport implements StoppableTasklet, org.springframework.beans.factory.InitializingBean
Tasklet
。システムコマンドは、注入された setTaskExecutor(TaskExecutor)
を使用して非同期で実行されます。外部プロセスがハングした場合にバッチジョブが永久にハングしないように、タイムアウト値を設定する必要があります。タスクレットは定期的に終了ステータスをチェックします(つまり、setCommand(String)
が実行を終了したか、setTimeout(long)
が期限切れになったか、ジョブが中断されました)。チェック間隔は setTerminationCheckInterval(long)
によって指定されます。ジョブの割り込みが検出されると、タスクレットの実行は JobInterruptedException
をスローすることによって直ちに終了します。setInterruptOnCancel(boolean)
は、タスクレットが(異常に)終了するときにまだ実行されている場合に、システムコマンドを実行するスレッドにタスクレットが割り込みを試みるかどうかを指定します。修飾子と型 | フィールドと説明 |
---|---|
protected static org.apache.commons.logging.Log | logger |
コンストラクターと説明 |
---|
SystemCommandTasklet() |
修飾子と型 | メソッドと説明 |
---|---|
void | afterPropertiesSet() |
void | beforeStep(StepExecution stepExecution) システムコマンド実行中の割り込みチェックのために StepExecution への参照を取得します。 |
RepeatStatus | execute(StepContribution contribution, ChunkContext chunkContext) システムコマンドを実行し、 SystemProcessExitCodeMapper を使用してその終了コードを ExitStatus にマップします。 |
void | setCommand(java.lang.String command) |
void | setEnvironmentParams(java.lang.String[] envp) |
void | setInterruptOnCancel(boolean interruptOnCancel) setTimeout(long) を超えた場合、またはユーザーがジョブを中断した場合、true タスクレットがシステムコマンドを実行しているスレッドを中断しようとします。 |
void | setJobExplorer(JobExplorer jobExplorer) |
void | setSystemProcessExitCodeMapper(SystemProcessExitCodeMapper systemProcessExitCodeMapper) |
void | setTaskExecutor(org.springframework.core.task.TaskExecutor taskExecutor) システムコマンド NB の実行に使用されるタスクエグゼキューターを設定します。同期タスクエグゼキューターの使用を避ける |
void | setTerminationCheckInterval(long checkInterval) タスクレットが終了ステータスをチェックする頻度の間隔。 |
void | setTimeout(long timeout) ミリ秒単位のタイムアウト。 |
void | setWorkingDirectory(java.lang.String dir) |
void | stop() setInterruptOnCancel(boolean) が true に設定されている場合にのみ、システムコマンドを実行するスレッドに割り込みます。 |
afterStep
@Nullable public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws java.lang.Exception
SystemProcessExitCodeMapper
を使用してその終了コードを ExitStatus
にマップします。Tasklet
の execute
contribution
- 現在のステップ実行を更新するために戻される変更可能な状態 chunkContext
- 再起動間ではなく、呼び出し間で共有される属性 RepeatStatus
null
を返すと、RepeatStatus.FINISHED
として解釈されます java.lang.Exception
- 実行中にエラーが発生した場合にスローされます。public void setCommand(java.lang.String command)
command
- 別のシステムプロセスで実行されるコマンド public void setEnvironmentParams(java.lang.String[] envp)
envp
- 設定されていない(または null に設定されている)ときに親プロセスから継承された環境パラメーター値。public void setWorkingDirectory(java.lang.String dir)
dir
- 生成されたプロセスの作業ディレクトリ。設定されていない(または null に設定されている)場合は親プロセスから継承されます。public void afterPropertiesSet() throws java.lang.Exception
org.springframework.beans.factory.InitializingBean
の afterPropertiesSet
java.lang.Exception
public void setJobExplorer(JobExplorer jobExplorer)
public void setSystemProcessExitCodeMapper(SystemProcessExitCodeMapper systemProcessExitCodeMapper)
systemProcessExitCodeMapper
- システムプロセスの戻り値を、タスクレットによって返される ExitStatus
にマップします。SimpleSystemProcessExitCodeMapper
がデフォルトで使用されます。public void setTimeout(long timeout)
timeout
- 外部プログラムの実行を継続できる時間の上限。public void setTerminationCheckInterval(long checkInterval)
checkInterval
- ミリ秒単位の時間間隔(デフォルトでは 1 秒)。public void beforeStep(StepExecution stepExecution)
StepExecution
への参照を取得します。StepExecutionListener
の beforeStep
StepExecutionListenerSupport
の beforeStep
stepExecution
- StepExecution
のインスタンス。public void setTaskExecutor(org.springframework.core.task.TaskExecutor taskExecutor)
taskExecutor
- TaskExecutor
のインスタンス。public void setInterruptOnCancel(boolean interruptOnCancel)
interruptOnCancel
- boolean は、プロセスを中断するかどうかを決定します public void stop()
setInterruptOnCancel(boolean)
が true に設定されている場合にのみ、システムコマンドを実行するスレッドに割り込みます。そうでない場合、基になるコマンドはタスクレットが終了する前に終了することが許可されます。StoppableTasklet
の stop
StoppableTasklet.stop()