I had created the
Thread object but the program can't be compiled by javac!It says:Can't solve symbol.
My code is:
public class testRun implements Runnable{
String id;
Thread thread=new Thread();
public testRun(String str){
id=str;
}
public void run(){
for(int i=0;i<1000;i++){
for(int j=1;j<100;j++);
try{
thread.sleep((int)1000*Math.random());
}catch(InterruptedException e){}
System.out.println(id+"is running");
}
}
}
class testC{
public static void main(String args[]){
testRun dog=new testRun("hello");
testRun cat=new testRun("JavaBean");
Thread t1=new Thread(dog);
Thread t2=new Thread(cat);
t1.start();
t2.start();
}
}
Add I find when I use sleep method and it can output few of results.But it can output many results
when I don't use the sleep method.Why? Thank you!