クラス SystemCommandTasklet

java.lang.ObjectSE
org.springframework.batch.core.step.tasklet.SystemCommandTasklet
実装されたすべてのインターフェース:
StoppableTaskletTaskletStepExecutionListenerStepListenerorg.springframework.beans.factory.InitializingBean

public class SystemCommandTasklet extends ObjectSE implements StepExecutionListener, StoppableTasklet, org.springframework.beans.factory.InitializingBean
システムコマンドを実行する Tasklet

システムコマンドは、挿入された setTaskExecutor(TaskExecutor) を使用して非同期的に実行されます。外部プロセスがハングした場合でもバッチジョブが永久にハングしないように、タイムアウト値を設定する必要があります。

タスクレットは終了ステータスを定期的にチェックします (つまり、setCommand(String...) が実行を終了したか、setTimeout(long) が期限切れになったか、ジョブが中断されました)。チェック間隔は setTerminationCheckInterval(long) で指定されます。

ジョブの割り込みが検出されると、タスクレットの実行は JobInterruptedException をスローして直ちに終了します。

setInterruptOnCancel(boolean) は、タスクレットが (異常に) 終了したときにシステムコマンドを実行するスレッドがまだ実行中の場合に、タスクレットがそのスレッドの中断を試行するかどうかを指定します。

作成者:
Robert Kasanicky, Will Schipp, Mahmoud Ben Hassine, Injae Kim
  • フィールドの詳細

    • logger

      protected static final org.apache.commons.logging.Log logger
  • コンストラクターの詳細

    • SystemCommandTasklet

      public SystemCommandTasklet()
  • メソッドの詳細

    • execute

      @Nullable public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws ExceptionSE
      システムコマンドを実行し、SystemProcessExitCodeMapper を使用してその終了コードを ExitStatus にマップします。
      次で指定:
      インターフェース Taskletexecute 
      パラメーター:
      contribution - 現在のステップ実行を更新するために戻される変更可能な状態
      chunkContext - 再起動間ではなく、呼び出し間で共有される属性
      戻り値:
      処理が継続可能かどうかを示す RepeatStatus null を返すと、RepeatStatus.FINISHED として解釈されます
      例外:
      ExceptionSE - 実行中にエラーが発生した場合にスローされます。
    • setCommandRunner

      public void setCommandRunner(CommandRunner commandRunner)
      CommandRunner 用の setter の注入。
      パラメーター:
      commandRunner - SystemCommandTasklet インスタンスによって使用される CommandRunner インスタンス。デフォルトは JvmCommandRunner です。
      導入:
      5.0
    • setCommand

      public void setCommand(StringSE... command)
      引数とともに実行するコマンドを設定します。例:
      setCommand("myCommand", "myArg1", "myArg2");
      パラメーター:
      command - 別のシステムプロセスで実行されるコマンド。
    • setEnvironmentParams

      public void setEnvironmentParams(StringSE[] envp)
      パラメーター:
      envp - 設定されていない(または null に設定されている)ときに親プロセスから継承された環境パラメーター値。
    • setWorkingDirectory

      public void setWorkingDirectory(StringSE dir)
      パラメーター:
      dir - 生成されたプロセスの作業ディレクトリ。設定されていない(または null に設定されている)場合は親プロセスから継承されます。
    • afterPropertiesSet

      public void afterPropertiesSet() throws ExceptionSE
      次で指定:
      インターフェース org.springframework.beans.factory.InitializingBeanafterPropertiesSet 
      例外:
      ExceptionSE
    • setJobExplorer

      public void setJobExplorer(JobExplorer jobExplorer)
    • setSystemProcessExitCodeMapper

      public void setSystemProcessExitCodeMapper(SystemProcessExitCodeMapper systemProcessExitCodeMapper)
      パラメーター:
      systemProcessExitCodeMapper - システムプロセスの戻り値を、タスクレットによって返される ExitStatus にマップします。SimpleSystemProcessExitCodeMapper がデフォルトで使用されます。
    • setTimeout

      public void setTimeout(long timeout)
      ミリ秒単位のタイムアウト。
      パラメーター:
      timeout - 外部プログラムの実行を継続できる時間の上限。
    • setTerminationCheckInterval

      public void setTerminationCheckInterval(long checkInterval)
      タスクレットが終了ステータスをチェックする頻度の間隔。
      パラメーター:
      checkInterval - ミリ秒単位の時間間隔(デフォルトでは 1 秒)。
    • beforeStep

      public void beforeStep(StepExecution stepExecution)
      システムコマンド実行中の割り込みチェックのために StepExecution への参照を取得します。
      次で指定:
      インターフェース StepExecutionListenerbeforeStep 
      パラメーター:
      stepExecution - StepExecution のインスタンス。
    • setTaskExecutor

      public void setTaskExecutor(org.springframework.core.task.TaskExecutor taskExecutor)
      システムコマンド NB の実行に使用されるタスクエグゼキューターを設定します。同期タスクエグゼキューターの使用を避ける
      パラメーター:
      taskExecutor - TaskExecutor のインスタンス。
    • setInterruptOnCancel

      public void setInterruptOnCancel(boolean interruptOnCancel)
      setTimeout(long) を超えた場合、またはユーザーがジョブを中断した場合、true タスクレットがシステムコマンドを実行しているスレッドを中断しようとします。デフォルトで false 
      パラメーター:
      interruptOnCancel - boolean は、プロセスを中断するかどうかを決定します
    • stop

      public void stop()
      setInterruptOnCancel(boolean) が true に設定されている場合にのみ、システムコマンドを実行するスレッドに割り込みます。そうでない場合、基になるコマンドはタスクレットが終了する前に終了することが許可されます。
      次で指定:
      インターフェース StoppableTaskletstop 
      導入:
      3.0
      関連事項: