Compare commits
8 Commits
dev
...
5770a41893
| Author | SHA1 | Date | |
|---|---|---|---|
| 5770a41893 | |||
| a919cf0a52 | |||
| 5612d6a24a | |||
| db530c1fed | |||
| 1fe9cf7b77 | |||
| 0d21b154ca | |||
| acba4c11d9 | |||
| d21fba0fc1 |
6
pom.xml
6
pom.xml
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>com.imyeyu.java</groupId>
|
<groupId>com.imyeyu.java</groupId>
|
||||||
<artifactId>timi-java</artifactId>
|
<artifactId>timi-java</artifactId>
|
||||||
<version>0.0.5</version>
|
<version>0.0.3</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
@@ -50,7 +50,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
<version>1.18.46</version>
|
<version>1.18.36</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</plugin>
|
</plugin>
|
||||||
@@ -92,7 +92,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
<version>1.18.46</version>
|
<version>1.18.40</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.junit.jupiter</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
|||||||
@@ -72,30 +72,6 @@ public interface TimiJava {
|
|||||||
return !isEmpty(object);
|
return !isEmpty(object);
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean hasEmpty(Object... objects) {
|
|
||||||
for (Object object : objects) {
|
|
||||||
if (isEmpty(object)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static boolean allNotEmpty(Object... objects) {
|
|
||||||
for (Object object : objects) {
|
|
||||||
if (isEmpty(object)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
static <T> T nullIfEmpty(T object) {
|
|
||||||
if (isEmpty(object)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return object;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 为空时取默认值
|
* 为空时取默认值
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -3,11 +3,9 @@ package com.imyeyu.java.thread;
|
|||||||
import com.imyeyu.java.bean.Callback;
|
import com.imyeyu.java.bean.Callback;
|
||||||
import com.imyeyu.java.bean.CallbackArg;
|
import com.imyeyu.java.bean.CallbackArg;
|
||||||
import com.imyeyu.java.bean.timi.TimiException;
|
import com.imyeyu.java.bean.timi.TimiException;
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@@ -42,41 +40,6 @@ public class AsyncRetryExecutor {
|
|||||||
@Getter
|
@Getter
|
||||||
private volatile boolean isRunning = false;
|
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<Exception> onRetryExhausted;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据构建器参数创建异步重试执行器
|
* 根据构建器参数创建异步重试执行器
|
||||||
*
|
*
|
||||||
@@ -99,9 +62,7 @@ public class AsyncRetryExecutor {
|
|||||||
}
|
}
|
||||||
if (0 < task.maxRetry && task.maxRetry < retryCount) {
|
if (0 < task.maxRetry && task.maxRetry < retryCount) {
|
||||||
// 超过重试次数
|
// 超过重试次数
|
||||||
if (task.onRetryExhausted != null) {
|
|
||||||
task.onRetryExhausted.handler(e);
|
task.onRetryExhausted.handler(e);
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// 重试
|
// 重试
|
||||||
@@ -118,13 +79,32 @@ public class AsyncRetryExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 使用默认参数创建执行器
|
* 构造器
|
||||||
*
|
*
|
||||||
* @param task 任务
|
* @author 夜雨
|
||||||
* @return 执行器实例
|
* @since 2025-11-06 23:37
|
||||||
*/
|
*/
|
||||||
public static AsyncRetryExecutor create(Task task) {
|
@Data
|
||||||
return new AsyncRetryExecutor(task);
|
@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<Exception> onRetryExhausted;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user