Package sonia.scm.repository.spi
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 Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptiondefault SyncAsyncExecutor
Creates anSyncAsyncExecutor
that will run tasks synchronously forDEFAULT_SWITCH_TO_ASYNC_IN_SECONDS
seconds.createExecutorWithSecondsToTimeout
(int switchToAsyncInSeconds) Creates anSyncAsyncExecutor
that will run tasks synchronously forswitchToAsyncInSeconds
seconds.createExecutorWithSecondsToTimeout
(int switchToAsyncInSeconds, int maxAsyncAbortSeconds) Creates anSyncAsyncExecutor
that will run tasks synchronously forswitchToAsyncInSeconds
seconds and will abort tasks after they ranmaxAsyncAbortSeconds
asynchronously.
-
Field Details
-
DEFAULT_SWITCH_TO_ASYNC_IN_SECONDS
static final int DEFAULT_SWITCH_TO_ASYNC_IN_SECONDS- See Also:
-
-
Method Details
-
createExecutorWithDefaultTimeout
Creates anSyncAsyncExecutor
that will run tasks synchronously forDEFAULT_SWITCH_TO_ASYNC_IN_SECONDS
seconds. The limit of asynchronous runtime is implementation dependant.- Returns:
- The executor.
-
createExecutorWithSecondsToTimeout
Creates anSyncAsyncExecutor
that will run tasks synchronously forswitchToAsyncInSeconds
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 to0
.- Returns:
- The executor.
-
createExecutorWithSecondsToTimeout
SyncAsyncExecutor createExecutorWithSecondsToTimeout(int switchToAsyncInSeconds, int maxAsyncAbortSeconds) Creates anSyncAsyncExecutor
that will run tasks synchronously forswitchToAsyncInSeconds
seconds and will abort tasks after they ranmaxAsyncAbortSeconds
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 to0
.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 afterswitchToAsyncInSeconds
immediately, set this to0
.- Returns:
- The executor.
-