class th extends Thread{
public void run() {
for(int i=0;i<100;++i){
try{
final int i1 = 55;
sleep(mills:i1;);
}catch(InterruptedException e){
e.printStackTrace();
}
if(i%3==0){
System.out.println(currentThread().getName()+":"+i);
}
if(i%2==0){
yield();
}
}
}
public th(String name){
super(name);
}
}
这多线程sleep方法为什么会报错,怎么把错误消除。
class th extends Thread {
@Override
public void run() {
for (int i = 0; i < 100; ++i) {
try {
final int i1 = 55;
sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (i % 3 == 0) {
System.out.println(currentThread().getName() + ":" + i);
}
if (i % 2 == 0) {
Thread.yield();
}
}
}
public th(String name) {
super(name);
}
}
有帮助点个采纳把