uws.job
Class JobThread

java.lang.Object
  extended by java.lang.Thread
      extended by uws.job.JobThread
All Implemented Interfaces:
java.lang.Runnable

public class JobThread
extends java.lang.Thread

An instance of this class is a thread dedicated to a job execution.

This thread is necessary associated with an AbstractJob instance. Thus the execution of this thread (Thread.start()) mainly consists in calling the AbstractJob.jobWork() method.

However its execution is possible only if the job phase is EXECUTING. The job phase constraint (=EXECUTING) is already checked so it is useless to check it again in AbstractJob.jobWork().

At the end of the execution the job must be correctly filled (cf AbstractJob.jobWork()) according to the execution conclusion:

In both cases the startTime and the endTime fields are already managed by AbstractJob so it is useless to change them.

Just after the job work the job phase is set to COMPLETED if no interruption has been detected, ABORTED otherwise.

If AbstractJob.jobWork() throws:

Version:
02/2011
Author:
Grégory Mantelet (CDS)
See Also:
AbstractJob.start(), AbstractJob.jobWork(), AbstractJob.abort(), AbstractJob.error(ErrorSummary), AbstractJob.error(UWSException), AbstractJob.getWorkError()

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
protected  boolean finished
          Indicates whether the AbstractJob.jobWork() has been called and finished, or not.
protected  AbstractJob job
          The job which contains all parameters for its execution and which must be filled at the end of the execution.
protected  UWSException lastError
          The last error which has occurred during the execution of this thread.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
JobThread(AbstractJob j)
          Builds the JobThread instance which will be used by the given job to execute its task.
 
Method Summary
 UWSException getError()
          Gets the last error which has occurred during the execution of this thread.
 AbstractJob getExecutedJob()
          Gets the job instance associated to this thread.
 boolean isFinished()
          Indicates whether the AbstractJob.jobWork() method has been called or not.
 void run()
           Tests the execution phase of the job: if not EXECUTING, nothing is done...the thread ends immediately.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

job

protected final AbstractJob job
The job which contains all parameters for its execution and which must be filled at the end of the execution.


lastError

protected UWSException lastError
The last error which has occurred during the execution of this thread.


finished

protected boolean finished
Indicates whether the AbstractJob.jobWork() has been called and finished, or not.

Constructor Detail

JobThread

public JobThread(AbstractJob j)
          throws UWSException
Builds the JobThread instance which will be used by the given job to execute its task.

Parameters:
j - The associated job.
Throws:
UWSException - If the given job is null.
Method Detail

getExecutedJob

public final AbstractJob getExecutedJob()
Gets the job instance associated to this thread.

Returns:
The associated job instance.

getError

public final UWSException getError()
Gets the last error which has occurred during the execution of this thread.

Returns:
The last error.

isFinished

public final boolean isFinished()
Indicates whether the AbstractJob.jobWork() method has been called or not.

Returns:
true if the job work is done, false otherwise.

run

public void run()
  1. Tests the execution phase of the job: if not EXECUTING, nothing is done...the thread ends immediately.
  2. Calls the AbstractJob.jobWork() method.
  3. Sets the finished flag to true.
  4. Changes the job phase to COMPLETED if not interrupted, else ABORTED.

If any InterruptedException occurs the job phase is only set to ABORTED.

If any UWSException occurs while the phase is EXECUTING the job phase is set to ERROR and an error summary is created.

Whatever is the exception, it will always be available thanks to the getError() after execution.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread
See Also:
AbstractJob.jobWork(), AbstractJob.setPhase(ExecutionPhase), AbstractJob.publishExecutionError(UWSException), UWSToolBox.publishErrorSummary(AbstractJob, String, ErrorType)