diff --git a/pom.xml b/pom.xml
index 2ea7280..238f263 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
com.imyeyu.java
timi-java
- 0.0.3
+ 0.0.4
jar
diff --git a/src/main/java/com/imyeyu/java/thread/AsyncRetryExecutor.java b/src/main/java/com/imyeyu/java/thread/AsyncRetryExecutor.java
index 9ffc7c3..93c3426 100644
--- a/src/main/java/com/imyeyu/java/thread/AsyncRetryExecutor.java
+++ b/src/main/java/com/imyeyu/java/thread/AsyncRetryExecutor.java
@@ -3,9 +3,11 @@ package com.imyeyu.java.thread;
import com.imyeyu.java.bean.Callback;
import com.imyeyu.java.bean.CallbackArg;
import com.imyeyu.java.bean.timi.TimiException;
+import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.Getter;
+import lombok.NoArgsConstructor;
import java.util.concurrent.TimeUnit;
@@ -40,6 +42,41 @@ public class AsyncRetryExecutor {
@Getter
private volatile boolean isRunning = false;
+ /**
+ * 任务
+ *
+ * @author 夜雨
+ * @since 2025-11-06 23:37
+ */
+ @Data
+ @Builder
+ @NoArgsConstructor
+ @AllArgsConstructor
+ public static class Task {
+
+ /** 必填回调方法 */
+ private Callback callback;
+
+ /** 最大重试次数,-1 为无限重试 */
+ @Builder.Default
+ private int maxRetry = DEFAULT_MAX_RETRY;
+
+ /** 重试间隔毫秒数 */
+ @Builder.Default
+ private long retryInterval = DEFAULT_RETRY_INTERVAL;
+
+ /** 线程名前缀 */
+ @Builder.Default
+ private String threadNamePrefix = DEFAULT_THREAD_NAME_PREFIX;
+
+ /** 是否设置为守护线程 */
+ @Builder.Default
+ private boolean daemon = DEFAULT_DAEMON;
+
+ /** 重试耗尽时的异常回调 */
+ private CallbackArg onRetryExhausted;
+ }
+
/**
* 根据构建器参数创建异步重试执行器
*
@@ -62,7 +99,9 @@ public class AsyncRetryExecutor {
}
if (0 < task.maxRetry && task.maxRetry < retryCount) {
// 超过重试次数
- task.onRetryExhausted.handler(e);
+ if (task.onRetryExhausted != null) {
+ task.onRetryExhausted.handler(e);
+ }
break;
}
// 重试
@@ -79,32 +118,13 @@ public class AsyncRetryExecutor {
}
/**
- * 构造器
+ * 使用默认参数创建执行器
*
- * @author 夜雨
- * @since 2025-11-06 23:37
+ * @param task 任务
+ * @return 执行器实例
*/
- @Data
- @Builder
- public static class Task {
-
- /** 必填回调方法 */
- private Callback callback;
-
- /** 最大重试次数,-1 为无限重试 */
- private int maxRetry = DEFAULT_MAX_RETRY;
-
- /** 重试间隔毫秒数 */
- private long retryInterval = DEFAULT_RETRY_INTERVAL;
-
- /** 线程名前缀 */
- private String threadNamePrefix = DEFAULT_THREAD_NAME_PREFIX;
-
- /** 是否设置为守护线程 */
- private boolean daemon = DEFAULT_DAEMON;
-
- /** 重试耗尽时的异常回调 */
- private CallbackArg onRetryExhausted;
+ public static AsyncRetryExecutor create(Task task) {
+ return new AsyncRetryExecutor(task);
}
/**