File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Why can't I use sleep method? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Why can Watch "Why can New topic
Author

Why can't I use sleep method?

Yashnoo lyo
Ranch Hand

Joined: Feb 17, 2003
Posts: 152
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!


When I face C# and Java I choose Java.
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

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

Joined: Feb 17, 2003
Posts: 152
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
 
subject: Why can't I use sleep method?