56 lines
1.8 KiB
Java
56 lines
1.8 KiB
Java
|
|
package com.youchain;
|
|||
|
|
|
|||
|
|
import com.youchain.businessdata.domain.AgvTask;
|
|||
|
|
import org.junit.jupiter.api.Test;
|
|||
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|||
|
|
import java.util.ArrayList;
|
|||
|
|
import java.util.List;
|
|||
|
|
import java.util.concurrent.ArrayBlockingQueue;
|
|||
|
|
import java.util.concurrent.BlockingQueue;
|
|||
|
|
|
|||
|
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
|||
|
|
public class EladminSystemApplicationTests {
|
|||
|
|
|
|||
|
|
@Test
|
|||
|
|
public void contextLoads() {
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public static void main(String[] args) {
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private static final int MAX_TASK_COUNT = 4;
|
|||
|
|
private static final long TIMEOUT_MS = 600000; // 10分钟,以毫秒为单位
|
|||
|
|
private long lastTaskTime = System.currentTimeMillis();
|
|||
|
|
private List<Integer> taskQueue = new ArrayList<>(MAX_TASK_COUNT);
|
|||
|
|
|
|||
|
|
@Test
|
|||
|
|
public void test(){
|
|||
|
|
List<Integer> taskLists=new ArrayList<>();
|
|||
|
|
taskLists.add(1);
|
|||
|
|
taskLists.add(2);
|
|||
|
|
taskLists.add(3);
|
|||
|
|
taskLists.add(4);
|
|||
|
|
taskLists.add(5);
|
|||
|
|
taskLists.add(6);
|
|||
|
|
|
|||
|
|
for(Integer id:taskLists) {
|
|||
|
|
try {
|
|||
|
|
taskQueue.add(id);
|
|||
|
|
if (taskQueue.size() >= MAX_TASK_COUNT) {
|
|||
|
|
System.out.println("任务已满足,当前任务数:" + taskQueue.size());
|
|||
|
|
taskQueue.clear();
|
|||
|
|
lastTaskTime = System.currentTimeMillis();
|
|||
|
|
} else if (System.currentTimeMillis() - lastTaskTime >= TIMEOUT_MS) {
|
|||
|
|
System.out.println("超过10分钟未满足4个任务,当前任务数:" + taskQueue.size());
|
|||
|
|
taskQueue.clear();
|
|||
|
|
lastTaskTime = System.currentTimeMillis();
|
|||
|
|
}
|
|||
|
|
} catch (Exception e) {
|
|||
|
|
throw new RuntimeException(e);
|
|||
|
|
}
|
|||
|
|
System.out.println(id);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|