任务相关

This commit is contained in:
李玉东 2025-09-18 11:41:46 +08:00
parent 3f1fd98f42
commit b8b67c1d3e
4 changed files with 13 additions and 38 deletions

View File

@ -27,16 +27,14 @@ import org.springframework.web.reactive.function.client.WebClient;
public abstract class AbtParentTask implements TaskAction {
protected final AtomicLong duringTime = new AtomicLong(0);
protected final ScheduledExecutorService schedule = Executors.newScheduledThreadPool(
1);
protected ScheduledFuture<?> scheduledFuture;
//任务数据
protected final ScenarioTask scenarioTask;
protected final String roomId;
protected WebClient webClient = WebClient.create();
ThreadPoolExecutor executor = new ThreadPoolExecutor(
protected ThreadPoolExecutor executor = new ThreadPoolExecutor(
5, // 核心线程数
10, // 最大线程数
60L, // 空闲线程存活时间
@ -52,20 +50,8 @@ public abstract class AbtParentTask implements TaskAction {
}
protected void start() {
scheduledFuture = schedule.scheduleAtFixedRate(() -> {
ScenarioWsParam scenarioWsParam = Global.roomParamMap.get(
scenarioTask.getScenarioId() + "_" + roomId);
if (scenarioWsParam == null) {
duringTime.getAndSet(1);
} else {
duringTime.getAndSet(scenarioWsParam.getMag());
}
}, 0, 1, TimeUnit.SECONDS);
}
protected abstract void finished();
protected abstract void setMag(int mag);
@ -85,13 +71,9 @@ public abstract class AbtParentTask implements TaskAction {
return scenarioTask.getTaskType();
}
public void cancelAllTask() {
if (scheduledFuture != null) {
scheduledFuture.cancel(true);
}
}
protected abstract void business();
}
// 自定义线程工厂

View File

@ -23,14 +23,8 @@ public class BattleRootTask extends AbtParentTask {
public void doSomeThing() {
//会知道想定ID, resourceId;
}
//固定间隔执行
@Override
protected void business() {
// Global.roomParamMap.get(scenarioTask.getScenarioId() + "," + this.roomId); 可以获取当前想定的步长
//战斗需要消耗弹药 按时间消耗30秒
//人员消耗
//可能会产生需求保障需求
}
@Override

View File

@ -11,6 +11,9 @@ import com.hivekion.room.func.TaskAction;
import com.hivekion.scenario.entity.ScenarioTask;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.env.Environment;
@ -26,7 +29,9 @@ import org.springframework.core.env.Environment;
@Slf4j
public class MoveRootTask extends AbtParentTask implements TaskAction {
protected final ScheduledExecutorService schedule = Executors.newScheduledThreadPool(
1);
protected ScheduledFuture<?> scheduledFuture;
private final double SPEED = 170;
private double accumulatedDistance = 0;
@ -84,10 +89,7 @@ public class MoveRootTask extends AbtParentTask implements TaskAction {
}
@Override
protected void business() {
}
@Override

View File

@ -28,10 +28,7 @@ public class SupplierTask extends AbtParentTask implements TaskAction {
}
@Override
protected void business() {
}
@Override