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

start and run method

Neelima Paramsetty

Joined: Jun 17, 2003
Posts: 16
i have the following code.for calling the run method,we have to use start() mehtod.though i am directly calling the run method through is working nicely.then waht for start();
Anybody help me?
class Thread1 implements Runnable
Thread t;
String name;
Thread1(String tname)
t=new Thread(this,name);;
public void run()
for(int i=0;i<8;i++)
class DemoJoin
public static void main(String args[])
new Thread1("one");

David O'Meara

Joined: Mar 06, 2001
Posts: 13459

Yep, except that by calling run() directly, your thread is being executed on a single thread and is not getting its own thread.
Try something like this:

Then try the same code using t.start()
Then only difference between my code and yours is the second Thread1 instance and the sleep block. (and it prints the name so you can see which Thread1 instance is running)
[ July 07, 2003: Message edited by: David O'Meara ]
I agree. Here's the link:
subject: start and run method
It's not a secret anymore!