| Author |
How to use the Runnable??
|
Yashnoo lyo
Ranch Hand
Joined: Feb 17, 2003
Posts: 152
|
|
Why I must create a Thread object when I use the run method? Despite I use the Runnable implements? 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(); } } //////////////////////////////////////////// when I delete the : Thread t1=new Thread(dog); Thread t2=new Thread(cat); use dog.start(); cat.start(); It can't run! saying:can't solve the dog?Why I must create a Thread Object? Thank you!
|
When I face C# and Java I choose Java.
|
 |
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12268
|
|
This is very basic Java. You should study the free Java tutorial available at java.sun.com or any of the other free resources. This forum exists for JavaServer Pages questions. Bill
|
 |
 |
|
|
subject: How to use the Runnable??
|
|
|