I'm getting an error: The method sleep(int) is undefined for the type Thread. I thought the sleep method is in the Thread class in Java.
import java.util.Random;
public class Thread implements Runnable {
String name;
int time;
Random r = new Random();
public Thread(String s){
name = s;
time = r.nextInt(999);
}
public void run() {
try{
System.out.printf("%s is sleeping for %d
", name, time);
Thread.sleep(time);
System.out.printf("%s is done", name);
} catch(Exception e ) {
}
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…