Package rife.database
Class DbKeepAlive
java.lang.Object
rife.scheduler.Executor
rife.database.DbKeepAlive
Periodic probe job to keep connections non-idle and probe for dead ones.
This is useful for MySQL/MariaDB, which close connections after a
period of inactivity.
This should be run using a scheduler. For example, to probe a datasource once an hour:
var keepAlive = new DbKeepAlive(datasource); scheduler.addExecutor(keepAlive); scheduler.addTask(keepAlive.createTask().frequency(Frequency.HOURLY));
There is one optional parameter.
query
- The dummy query to send. If not specified, the default is "select 1".
- Since:
- 1.6.2
-
Field Summary
Fields inherited from class rife.scheduler.Executor
DEFAULT_RESCHEDULE_DELAY
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
executeTask
(Task task) Needs to be implemented with the logic that should happen when the scheduler executes a task.Methods inherited from class rife.scheduler.Executor
createTask, getHandledTaskType, getRescheduleDelay, getScheduler
-
Constructor Details
-
DbKeepAlive
-
-
Method Details
-
executeTask
Description copied from class:Executor
Needs to be implemented with the logic that should happen when the scheduler executes a task.Sometimes tasks fail to be executed, or the right conditions can't be met. In that case, returning
false
from this method will make the scheduler reschedule the same task. The delay that is used for rescheduling is determined by this class'sExecutor.getRescheduleDelay()
method.- Specified by:
executeTask
in classExecutor
- Parameters:
task
- the task that needs to be executed.- Returns:
true
if the task successfully executed, orfalse
if the task needs to be rescheduled- See Also:
-