This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why can't I use sleep method?

 
Yashnoo lyo
Ranch Hand
Posts: 152
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can't *resolve* symbol.

Your error is: C:\testRun.java:12: cannot resolve symbol
symbol : method sleep (double)

Your code:
thread.sleep((int)1000*Math.random());

Breaks down to Math.random() returns a double, multiply that by the result of casting 1000 to an integer. Which gives you a double. Which is why javac cannot resolve the method sleep(double).


And what does this have to do with JSP?
 
Yashnoo lyo
Ranch Hand
Posts: 152
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much for your help! I want to test the Thread class only and don't want to insert it to jsp.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic