Class BackgroundTask

  • All Implemented Interfaces:
    BlockingTask, Task

    public class BackgroundTask
    extends Object
    implements BlockingTask
    A sleepless blocking task that runs in a Thread the background. The execution is blocked until the task budget is exhausted. All background tasks are constrained by a time budget.
    • Method Detail

      • run

        public <T> boolean run​(Predicate<T> predicate,
                               T payload)
        Description copied from interface: BlockingTask
        Run the task
        Specified by:
        run in interface BlockingTask
        Type Parameters:
        T - The type of the payload passed to the predicate when testing the task
        Parameters:
        predicate - the task as a predicate. The result of the predicate is used to check if the task has completed or not. The predicate must return true if the execution has completed or false otherwise. Failures on the task should be handled on the predicate using the payload as wrapper for In/Out if necessary
        payload - a payload to be passed to the task
        Returns:
        true if the task has completed successfully or false if: 1) the budget is exhausted or 2) the task was interrupted.
      • run

        public boolean run​(BooleanSupplier supplier)
        Description copied from interface: BlockingTask
        Run the task
        Specified by:
        run in interface BlockingTask
        Parameters:
        supplier - the task as a boolean supplier. The result is used to check if the task has completed or not. The supplier must return true if the execution has completed or false otherwise.
        Returns:
        true if the task has completed successfully or false if: 1) the budget is exhausted or 2) the task was interrupted.
      • elapsed

        public Duration elapsed()
        Description copied from interface: Task
        How long it took to run the task
        Specified by:
        elapsed in interface Task
        Returns:
        The duration to execute the task