You can use a counter variable to keep track of the number of iterations in the foreach loop. After every 10 iterations, you can pause the execution for 1 second using a Timer. Here's an example:

int counter = 0;
foreach (InstList instList : instLists) {
    // Your code logic for each iteration here
    
    counter++;
    
    if (counter % 10 == 0) {
        try {
            Thread.sleep(1000); // Pause for 1 second
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

Make sure to handle the InterruptedException properly in case the sleep is interrupted.

Java Foreach Loop with Timer: Pausing Every 10 Iterations

原文地址: https://www.cveoy.top/t/topic/bdTL 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录