Interface TaskListener
- All Known Subinterfaces:
OnceTaskListener
public interface TaskListener
Task listener callback, used in scenarios such as: one-time delayed tasks, scheduled tasks, lightweight controllable delayed tasks, lightweight periodic persistence helper functions, and other extended scenarios.
Documentation
These usage scenarios share a common feature: listener callbacks. The interface provides 4 methods, as follows: 1.CommonTaskListener.onUpdate(), listener callback 2.CommonTaskListener.triggerUpdate(), whether to trigger theCommonTaskListener.onUpdate()listener callback method 3.CommonTaskListener.onException(Throwable), exception callback. If an exception is thrown during the execution ofCommonTaskListener.triggerUpdate()andCommonTaskListener.onUpdate()methods, it will be caught by this method. 4.CommonTaskListener.getExecutor(), specify the executor to run the above methods, with the goal of not occupying business threads.
- Since:
- 21.9
- Author:
- 渔民小镇
- date:
- 2023-12-06
-
Method Details
-
triggerUpdate
default boolean triggerUpdate()Whether to trigger the onUpdate listener callback method- Returns:
- true to execute the onUpdate method
-
onUpdate
void onUpdate()Timer listener callback -
onException
Exception callbackWhen the triggerUpdate or onUpdate method throws an exception, it will be passed here.
- Parameters:
e- e
-
getExecutor
The executor for executing onUpdateIf null is returned, it will be executed within HashedWheelTimer. If there are time-consuming tasks, such as those involving IO operations, it is recommended to specify an executor to run the current callback (onUpdate method) to avoid blocking other tasks.
Exampledefault Executor getExecutor() { // Time-consuming task, specify an executor to consume the current onUpdate return TaskKit.getCacheExecutor(); }- Returns:
- If the return value is null, execution will use the current thread (default HashedWheelTimer), otherwise, the specified executor will be used.
-