Interface BackgroundTask<R>

Type Parameters:
R - result type
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface BackgroundTask<R>
A single background computation managed by MDI's simulation infrastructure.

A background task differs from a step-oriented simulation in one important way: its entire calculation is expressed by one invocation of execute(TaskContext). MDI adapts that invocation to a SimulationEngine, so the task receives the same daemon-thread execution, cooperative cancellation, coalesced progress reporting, and EDT callback guarantees as a simulation without requiring application code to manufacture a one-step Simulation implementation.

The method always runs off the Swing event-dispatch thread. It may return null. Long-running implementations should periodically call TaskContext.throwIfCancellationRequested() or inspect TaskContext.isCancellationRequested().

  • Method Summary

    Modifier and Type
    Method
    Description
    Perform the computation.
  • Method Details

    • execute

      R execute(TaskContext context) throws Exception
      Perform the computation.
      Parameters:
      context - services and cancellation state for this invocation
      Returns:
      the computed result, which may be null
      Throws:
      Exception - if the computation fails