File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes How to use the Runnable?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "How to use the Runnable??" Watch "How to use the Runnable??" New topic

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){
public void run(){
for(int i=0;i<1000;i++){
for(int j=1;j<100;j++);
}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);
when I delete the :
Thread t1=new Thread(dog);
Thread t2=new Thread(cat);
use dog.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

Joined: Mar 22, 2000
Posts: 13037
This is very basic Java. You should study the free Java tutorial available at or any of the other free resources. This forum exists for JavaServer Pages questions.
I agree. Here's the link:
subject: How to use the Runnable??
It's not a secret anymore!