Package net.sf.basedb.core
Class InternalJobQueue
java.lang.Object
java.util.TimerTask
net.sf.basedb.core.InternalJobQueue
- All Implemented Interfaces:
Runnable
A simple implementation of a job queue that executes jobs
in order of priority and longest waiting time. To allow quick jobs
like importing raw data or reporters to run it is possible to
reserve slots per
Job.ExecutionTime
setting. The configuration
is done in the base.config
file with the following settings:
Setting | Default/possible value(s) | Description |
---|---|---|
jobqueue.internal.enabled | true | false | If the internal job queue is enabled or not. Do not disable the job queue if you don't have another external job queue manager. It is possible to use both an external and internal job queue. |
jobqueue.internal.checkinterval | 30 | The interval, in seconds, that the job queue checks the database for new jobs. |
jobqueue.internal.maxthreadpriority | Thread.NORM_PRIORITY - 1 |
The maximum thread priority for the threads that execute jobs.
See Thread.setPriority(int) for possible values.
|
jobqueue.internal.shortest.threads | 1 | Number of threads to reserve for jobs with an estimated execution time of less than one minute. Jobs with this setting may also use threads from the other "slower" slots. |
jobqueue.internal.shortest.threadpriority | Thread.NORM_PRIORITY - 1 |
The thread priority to use when executing jobs in this slot.
See Thread.setPriority(int) for possible values.
|
jobqueue.internal.short.threads | 1 | Number of threads to reserve for jobs with an estimated execution time between one and ten minutes. Jobs with this setting may also use threads from the other "slower" slots. |
jobqueue.internal.short.threadpriority | Thread.NORM_PRIORITY - 1 |
The thread priority to use when executing jobs in this slot.
See Thread.setPriority(int) for possible values.
|
jobqueue.internal.medium.threads | 2 | Number of threads to reserve for jobs with an estimated execution time less than one hour. Jobs with this setting may also use threads from the other "slower" slots. |
jobqueue.internal.medium.threadpriority | Thread.NORM_PRIORITY - 2 |
The thread priority to use when executing jobs in this slot.
See Thread.setPriority(int) for possible values.
|
jobqueue.internal.long.threads | 4 | Number of threads to reserve for jobs with an estimated execution time more than one hour. Jobs with this setting may not use threads from the other slots. |
jobqueue.internal.long.threadpriority | Thread.NORM_PRIORITY - 2 |
The thread priority to use when executing jobs in this slot.
See Thread.setPriority(int) for possible values.
|
- Version:
- 2.0
- Author:
- Nicklas
- Last modified
- $Date: 2024-10-30 13:32:46 +0100 (Wed, 30 Oct 2024) $
-
Nested Class Summary
Modifier and TypeClassDescriptionprivate static class
Our own keyring containing the permissions we need to execute the jobs.private class
Encapsulates the running of a job in a separate thread. -
Field Summary
Modifier and TypeFieldDescriptionprivate int
Timeout to wait for jobs to act on the ABORT signal when shutting down BASE.private boolean
If thePluginDefinitionData.getUseInternalJobQueue()
setting should be ignored or not.private static final Logger
Log job queue events.private final Map<Job.ExecutionTime,
Integer> The maximum number of threads that are allowed in each slot.private long
Time when the next status update request for external jobs is scheduled.private final Map<Job.ExecutionTime,
Integer> The thread priority to use when executing jobs in each slot.private final Set<InternalJobQueue.JobRunner>
Holds all currently executing jobs.private final ThreadGroup
The group were all job runners are placed.private final SessionControl
The job queues session controller.private static SignalReceiver
Use the local signal receiver only.private final Map<Job.ExecutionTime,
Integer> The current number of threads executing in each slot. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprivate void
(package private) void
close()
Cleanupstatic SignalReceiver
Get the signal receiver used by the internal job queue.private void
jobDone
(InternalJobQueue.JobRunner runner) Called from aInternalJobQueue.JobRunner
when it has finished executing the job.private void
void
run()
Check the database for jobs that are waiting to be executed.private void
sendErrorMessage
(SessionControl impersonated, int jobId, Throwable ex) Methods inherited from class java.util.TimerTask
cancel, scheduledExecutionTime
-
Field Details
-
log
Log job queue events. -
sc
The job queues session controller. We are logging in using our own keyring:InternalJobQueue.JobQueueKeyring
. -
usedSlots
The current number of threads executing in each slot. -
maxSlots
The maximum number of threads that are allowed in each slot. -
priorities
The thread priority to use when executing jobs in each slot. -
runnersGroup
The group were all job runners are placed. -
runners
Holds all currently executing jobs. -
ignoreUseInternalJobQueueFlag
private boolean ignoreUseInternalJobQueueFlagIf thePluginDefinitionData.getUseInternalJobQueue()
setting should be ignored or not. -
closeTimeout
private int closeTimeoutTimeout to wait for jobs to act on the ABORT signal when shutting down BASE. Default value is 20 seconds. -
nextStatusUpdateRequest
private long nextStatusUpdateRequestTime when the next status update request for external jobs is scheduled. -
signalReceiver
Use the local signal receiver only.
-
-
Constructor Details
-
InternalJobQueue
InternalJobQueue()Create the job queue. The one and only instance is created by Application.start
-
-
Method Details
-
getSignalReceiver
Get the signal receiver used by the internal job queue. If the internal job queue is disabled aLocalSignalReceiver
is created on the first call to this method.- Returns:
- A signal receiver object
- Since:
- 2.7
-
run
public void run()Check the database for jobs that are waiting to be executed. We sort the jobs by priority and creation time and try to execute them in that order. Each job is encapsulated in aInternalJobQueue.JobRunner
object which is started in it's own thread. -
checkInternalJobQueue
private void checkInternalJobQueue() -
requestExternalStatusUpdate
private void requestExternalStatusUpdate() -
jobDone
Called from aInternalJobQueue.JobRunner
when it has finished executing the job. IT MUST NEVER FORGET TO CALL THIS METHOD. -
sendErrorMessage
-
close
void close()Cleanup
-