Class JobExecution

java.lang.Object
org.springframework.batch.core.Entity
org.springframework.batch.core.job.JobExecution
All Implemented Interfaces:
Serializable

public class JobExecution extends Entity
Batch domain object representing the execution of a job.
Author:
Lucas Ward, Michael Minella, Mahmoud Ben Hassine, Dimitrios Liapis, Taeik Lim
See Also:
  • Constructor Details

    • JobExecution

      public JobExecution(long id, JobInstance jobInstance, JobParameters jobParameters)
      Create a new JobExecution instance. Because a JobExecution is not valid unless the job instance is set, this constructor is the only valid one from a modeling point of view.
      Parameters:
      id - of the JobExecution.
      jobInstance - The job instance of which this execution is a part.
      jobParameters - A JobParameters instance for this JobExecution.
  • Method Details

    • getJobParameters

      public JobParameters getJobParameters()
      Returns:
      The current JobParameters.
    • getEndTime

      public @Nullable LocalDateTime getEndTime()
      Returns:
      The current end time.
    • setJobInstance

      public void setJobInstance(JobInstance jobInstance)
      Set the JobInstance used by the JobExecution.
      Parameters:
      jobInstance - The JobInstance used by the JobExecution.
    • setEndTime

      public void setEndTime(LocalDateTime endTime)
      Set the end time.
      Parameters:
      endTime - The LocalDateTime to be used for the end time.
    • getStartTime

      public @Nullable LocalDateTime getStartTime()
      Returns:
      The current start time.
    • setStartTime

      public void setStartTime(LocalDateTime startTime)
      Set the start time.
      Parameters:
      startTime - The LocalDateTime to be used for the start time.
    • getStatus

      public BatchStatus getStatus()
      Returns:
      The current BatchStatus.
    • setStatus

      public void setStatus(BatchStatus status)
      Set the value of the status field.
      Parameters:
      status - The status to set.
    • upgradeStatus

      public void upgradeStatus(BatchStatus status)
      Upgrade the status field if the provided value is greater than the existing one. Clients using this method to set the status can be sure to not overwrite a failed status with a successful one.
      Parameters:
      status - The new status value.
    • getJobInstanceId

      public long getJobInstanceId()
      Convenience getter for the id of the enclosing job instance. Useful for DAO implementations.
      Returns:
      the id of the enclosing job instance.
    • setExitStatus

      public void setExitStatus(ExitStatus exitStatus)
      Parameters:
      exitStatus - The ExitStatus instance to be used for job execution.
    • getExitStatus

      public ExitStatus getExitStatus()
      Returns:
      the exitStatus.
    • getJobInstance

      public JobInstance getJobInstance()
      Returns:
      the Job instance that is executing.
    • getStepExecutions

      public Collection<StepExecution> getStepExecutions()
      Accessor for the step executions.
      Returns:
      the step executions that were registered.
    • isRunning

      public boolean isRunning()
      Test if this JobExecution indicates that it is running. Note that this does not necessarily mean that it has been persisted.
      Returns:
      true if the status is one of the running statuses.
      See Also:
    • isStopping

      public boolean isStopping()
      Test if this JobExecution indicates that it has been signalled to stop.
      Returns:
      true if the status is BatchStatus.STOPPING.
    • setExecutionContext

      public void setExecutionContext(ExecutionContext executionContext)
      Sets the ExecutionContext for this execution.
      Parameters:
      executionContext - The context.
    • getExecutionContext

      public ExecutionContext getExecutionContext()
      Returns the ExecutionContext for this execution. The content is expected to be persisted after each step completion (successful or not).
      Returns:
      The ExecutionContext.
    • getCreateTime

      public LocalDateTime getCreateTime()
      Returns:
      the time when this execution was created.
    • setCreateTime

      public void setCreateTime(LocalDateTime createTime)
      Parameters:
      createTime - The creation time of this execution.
    • addStepExecution

      public void addStepExecution(StepExecution stepExecution)
      Add a step execution.
      Parameters:
      stepExecution - The stepExecution execution to be added.
    • addStepExecutions

      public void addStepExecutions(List<StepExecution> stepExecutions)
      Add some step executions.
      Parameters:
      stepExecutions - The step executions to add to the current list.
    • getLastUpdated

      public @Nullable LocalDateTime getLastUpdated()
      Get the date representing the last time this JobExecution was updated in the JobRepository.
      Returns:
      a LocalDateTime object representing the last time this JobExecution was updated.
    • setLastUpdated

      public void setLastUpdated(LocalDateTime lastUpdated)
      Set the last time this JobExecution was updated.
      Parameters:
      lastUpdated - The LocalDateTime instance to which to set the job execution's lastUpdated attribute.
    • getFailureExceptions

      public List<Throwable> getFailureExceptions()
      Retrieve a list of exceptions.
      Returns:
      the List of Throwable objects.
    • addFailureException

      public void addFailureException(Throwable t)
      Add the provided throwable to the failure exception list.
      Parameters:
      t - A Throwable instance to be added failure exception list.
    • getAllFailureExceptions

      public List<Throwable> getAllFailureExceptions()
      Return all failure causing exceptions for this JobExecution, including step executions.
      Returns:
      a List<Throwable> containing all exceptions causing failure for this JobExecution.
    • toString

      public String toString()
      Description copied from class: Entity
      Creates a string representation of the Entity, including the id, version, and class name.
      Overrides:
      toString in class Entity