Package rife.database

Class DbKeepAlive

java.lang.Object
rife.scheduler.Executor
rife.database.DbKeepAlive

public class DbKeepAlive extends Executor
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
  • Constructor Details

    • DbKeepAlive

      public DbKeepAlive(Datasource datasource)
  • Method Details

    • executeTask

      public boolean executeTask(Task task)
      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's Executor.getRescheduleDelay() method.

      Specified by:
      executeTask in class Executor
      Parameters:
      task - the task that needs to be executed.
      Returns:
      true if the task successfully executed, or false if the task needs to be rescheduled
      See Also: