package com.youchain;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.ArrayList;
import java.util.List;

@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);
        }
    }
}

