Package com.simplicite.util
Class CronJob
- java.lang.Object
-
- java.lang.Thread
-
- com.simplicite.util.CronJob
-
- All Implemented Interfaces:
java.lang.Runnable
public class CronJob extends java.lang.Thread
Job associated with one method of object
Job is launched by the CronTable or by one asynchronous Action
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
JOB_STATUS_EXCEPTION
Job has terminated throwing exceptionstatic java.lang.String
JOB_STATUS_INITIAL
Initialized statusstatic java.lang.String
JOB_STATUS_INTERRUPT
Interrupt is requestedstatic java.lang.String
JOB_STATUS_PAUSE
Pause is requestedstatic java.lang.String
JOB_STATUS_RESUME
Resume is requestedstatic java.lang.String
JOB_STATUS_RUNNING
Job is runningstatic java.lang.String
JOB_STATUS_SLEEP
Job is sleepingstatic java.lang.String
JOB_STATUS_STOPPED
Stopped thru interruption exceptionstatic java.lang.String
JOB_STATUS_TERMINATED
Job has terminated
-
Constructor Summary
Constructors Constructor Description CronJob(CronDefinition def)
Asynchronous constructor on a new job instance of Object and GrantCronJob(ObjectDB object, Action action, Grant grant)
Job constructorCronJob(ObjectDB object, Action action, Grant grant, java.util.Map<java.lang.String,java.lang.String> params)
Job constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
checkForInterruptAndStop(ObjectDB obj)
To call periodically in the asynchronous method to throw one InterruptedException
when one user has requested it to stop.static void
clearCache()
java.lang.String
getJobId()
Standard row_id of the Jobjava.lang.String
getJobUid()
Unique key in DB as a String: [thread id]-[timestamp in ms]-[job hash]static java.util.Map<java.lang.String,java.lang.Long>
getRunningJobs(java.lang.String status)
Running jobs by name with duration from beginning in secondsstatic java.lang.String
getStatus(ObjectDB obj)
Get the status of the current CronJob threadvoid
run()
Launch the Jobstatic void
setStatus(ObjectDB obj, java.lang.String status)
Set the status of the current CronJob threadstatic java.lang.String
updateStatus(java.lang.String jobRowId, java.lang.String status)
Update the AsyncJob status and the start/end dates-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
-
-
-
Field Detail
-
JOB_STATUS_INITIAL
public static final java.lang.String JOB_STATUS_INITIAL
Initialized status- See Also:
- Constant Field Values
-
JOB_STATUS_RUNNING
public static final java.lang.String JOB_STATUS_RUNNING
Job is running- See Also:
- Constant Field Values
-
JOB_STATUS_TERMINATED
public static final java.lang.String JOB_STATUS_TERMINATED
Job has terminated- See Also:
- Constant Field Values
-
JOB_STATUS_EXCEPTION
public static final java.lang.String JOB_STATUS_EXCEPTION
Job has terminated throwing exception- See Also:
- Constant Field Values
-
JOB_STATUS_INTERRUPT
public static final java.lang.String JOB_STATUS_INTERRUPT
Interrupt is requested- See Also:
- Constant Field Values
-
JOB_STATUS_STOPPED
public static final java.lang.String JOB_STATUS_STOPPED
Stopped thru interruption exception- See Also:
- Constant Field Values
-
JOB_STATUS_PAUSE
public static final java.lang.String JOB_STATUS_PAUSE
Pause is requested- See Also:
- Constant Field Values
-
JOB_STATUS_RESUME
public static final java.lang.String JOB_STATUS_RESUME
Resume is requested- See Also:
- Constant Field Values
-
JOB_STATUS_SLEEP
public static final java.lang.String JOB_STATUS_SLEEP
Job is sleeping- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CronJob
public CronJob(CronDefinition def)
Asynchronous constructor on a new job instance of Object and Grant- Parameters:
def
- Cron job definition
-
CronJob
public CronJob(ObjectDB object, Action action, Grant grant)
Job constructor- Parameters:
object
- Objectaction
- Action to call in a new threadgrant
- User rights
-
-
Method Detail
-
clearCache
public static void clearCache()
-
getJobId
public java.lang.String getJobId()
Standard row_id of the Job- Returns:
- job id
-
getJobUid
public java.lang.String getJobUid()
Unique key in DB as a String: [thread id]-[timestamp in ms]-[job hash]- Returns:
- job Unique id
-
updateStatus
public static java.lang.String updateStatus(java.lang.String jobRowId, java.lang.String status)
Update the AsyncJob status and the start/end dates- Parameters:
jobRowId
- Job Idstatus
- Status- Returns:
- datetime of update
-
run
public void run()
Launch the Job- Specified by:
run
in interfacejava.lang.Runnable
- Overrides:
run
in classjava.lang.Thread
-
checkForInterruptAndStop
public static void checkForInterruptAndStop(ObjectDB obj) throws java.lang.InterruptedException
To call periodically in the asynchronous method to throw one InterruptedException
when one user has requested it to stop. If this method is never called,
the thread won't be stopped before its end of execution
even if one interruption has been requested by a user
If the caller needs to end properly (without exception),
use only the checkForInterruptRequest method.- Parameters:
obj
- ObjectDB- Throws:
java.lang.InterruptedException
- InterruptedException
-
getStatus
public static java.lang.String getStatus(ObjectDB obj)
Get the status of the current CronJob thread- Parameters:
obj
- ObjectDB- Returns:
- Status if exists, or null
-
setStatus
public static void setStatus(ObjectDB obj, java.lang.String status)
Set the status of the current CronJob thread- Parameters:
obj
- ObjectDBstatus
- Status
-
getRunningJobs
public static java.util.Map<java.lang.String,java.lang.Long> getRunningJobs(java.lang.String status)
Running jobs by name with duration from beginning in seconds
-
-