Java 代码:每隔 2 分钟检测计数是否超过 10 次
public class Test {
public static void main(String[] args) {
int count = 0;
long startTime = System.currentTimeMillis();
long endTime = startTime + 2 * 60 * 1000;
while (System.currentTimeMillis() < endTime) {
count++;
// 如果 count > 10,那么结束时间就是当前时间
if (count > 10) {
endTime = System.currentTimeMillis();
System.out.println('warn');
}
}
}
}
原文地址: https://www.cveoy.top/t/topic/ll6e 著作权归作者所有。请勿转载和采集!