java - Shift Thread Start / for循环加倍?
问题描述
我试图不同时启动我的所有线程,所以当我第一次循环我的 for 循环时,我希望它们睡觉。奇怪的是,他们通过 (i == 0) 两次。我看不到什么?谢谢你的建议!这是输出:
- i: 0, iD: 0, 当前时间: 1612092185653
- i: 0, iD: 0, 当前时间: 1612092185664
- i: 0, iD: 1, 当前时间: 1612092185709
- i: 0, iD: 1, 当前时间: 1612092185718
- i: 0, iD: 2, 当前时间: 1612092185756
- i: 0, iD: 2, 当前时间: 1612092185765
- i: 0, iD: 3, 当前时间: 1612092185811
- i: 0, iD: 3, 当前时间: 1612092185823
- i: 0, iD: 4, 当前时间: 1612092185863
- i: 0, iD: 4, 当前时间: 1612092185870
public static Result compute(ServiceBot bot) throws InterruptedException {
for (int i = 0; i < orderList.size(); i++) {
System.out.println("Was ist mit i? :" + i);
if (i == 0) {
int iD = bot.getID();
switch (iD) {
case 0:
System.out.println("i: " + i + ", iD: " + iD + ", CurrentTime: " + System.currentTimeMillis());
break;
case 1:
Thread.sleep(50);
System.out.println("i: " + i + ", iD: " + iD + ", CurrentTime: " + System.currentTimeMillis());
break;
case 2:
Thread.sleep(100);
System.out.println("i: " + i + ", iD: " + iD + ", CurrentTime: " + System.currentTimeMillis());
break;
case 3:
Thread.sleep(150);
System.out.println("i: " + i + ", iD: " + iD + ", CurrentTime: " + System.currentTimeMillis());
break;
case 4:
Thread.sleep(200);
System.out.println("i: " + i + ", iD: " + iD + ", CurrentTime: " + System.currentTimeMillis());
break;
}
}
boolean dummyBool = orderList.get(i).getUnhandled();
if (dummyBool = true) {
bot.doStuff();
Thread.sleep(sleep);
} else {
bot.doNothing();
}
}
int wait = 50;
return new Result(wait);
}
解决方案
推荐阅读
- image - 如何在 MainActivity 中导入图像
- reactjs - 使用 react 和 chartjs-plugin-streaming 流式传输实时数据已暂停
- reactjs - 如何显示从 Strapi 的 WYSIWYG 到 NextJS 的 UI 的文本格式?
- python - 有点复杂的熊猫数据透视表
- amazon-web-services - 使用外部电子邮件提供商而不是 AWS Cognito 来发送用户确认电子邮件
- html - StickyEnd 不适用于复选框
- c# - ExpandoObject 可以有一个强类型的父对象吗?
- python - 如何在 Python Falcon 应用程序中设置 X 帧选项?
- celery - 我应该实现 Apache Airflow 还是只使用 Celery
- javascript - 来自 API 的数据:检索特定数据 JS