Interface SyncAsyncExecutorProvider


public interface SyncAsyncExecutorProvider
Use this provider to get SyncAsyncExecutor instances to execute a number of normally short-lived tasks, that should be run asynchronously (or even be skipped) whenever they take too long in summary.

The goal of this is a "best effort" approach: The submitted tasks are run immediately when they are submitted, unless a given timespan (switchToAsyncInSeconds) has passed. From this moment on the tasks are put into a queue to be processed asynchronously. If even then they take too long and their accumulated asynchronous runtime exceeds another limit (maxAsyncAbortSeconds), the tasks are skipped.

Note that whenever a task has been started either synchronously or asynchronously it will neither be terminated nor switched from foreground to background execution, so this will only work well for short-living tasks. A long running task can still block this for longer than the configured amount of seconds.

  • Field Details

    • DEFAULT_SWITCH_TO_ASYNC_IN_SECONDS

      static final int DEFAULT_SWITCH_TO_ASYNC_IN_SECONDS
      See Also:
  • Method Details

    • createExecutorWithDefaultTimeout

      default SyncAsyncExecutor createExecutorWithDefaultTimeout()
      Creates an SyncAsyncExecutor that will run tasks synchronously for DEFAULT_SWITCH_TO_ASYNC_IN_SECONDS seconds. The limit of asynchronous runtime is implementation dependant.
      Returns:
      The executor.
    • createExecutorWithSecondsToTimeout

      SyncAsyncExecutor createExecutorWithSecondsToTimeout(int switchToAsyncInSeconds)
      Creates an SyncAsyncExecutor that will run tasks synchronously for switchToAsyncInSeconds seconds. The limit of asynchronous runtime is implementation dependant.
      Parameters:
      switchToAsyncInSeconds - The amount of seconds submitted tasks will be run synchronously. After this time, further tasks will be run asynchronously. To run all tasks asynchronously no matter what, set this to 0.
      Returns:
      The executor.
    • createExecutorWithSecondsToTimeout

      SyncAsyncExecutor createExecutorWithSecondsToTimeout(int switchToAsyncInSeconds, int maxAsyncAbortSeconds)
      Creates an SyncAsyncExecutor that will run tasks synchronously for switchToAsyncInSeconds seconds and will abort tasks after they ran maxAsyncAbortSeconds asynchronously.
      Parameters:
      switchToAsyncInSeconds - The amount of seconds submitted tasks will be run synchronously. After this time, further tasks will be run asynchronously. To run all tasks asynchronously no matter what, set this to 0.
      maxAsyncAbortSeconds - The amount of seconds, tasks that were started asynchronously may run in summary before remaining tasks will not be executed at all anymore. To abort all tasks that are submitted after switchToAsyncInSeconds immediately, set this to 0.
      Returns:
      The executor.