wood burning stoves 2.0*
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "start and run method" Watch "start and run method" New topic
Author

start and run method

Neelima Paramsetty
Greenhorn

Joined: Jun 17, 2003
Posts: 16
sir,
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 run.it is working nicely.then waht for start();
Anybody help me?
class Thread1 implements Runnable
{
Thread t;
String name;
Thread1(String tname)
{
name=tname;
t=new Thread(this,name);
t.run();
}
public void run()
{
for(int i=0;i<8;i++)
{
System.out.println(i);
}
}
}
class DemoJoin
{
public static void main(String args[])
{
new Thread1("one");
}

}
thanks
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Calling the run method does not start a new thread. When you call start on a Thread object, the JVM starts a physical thread on the OS and then calls run. So if you call run directly, you are just using the calling thread, not creating a new thread.


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: start and run method
 
Similar Threads
join() method usage
start and run method
Main Thread is Alive ?
how to call a method based on the thread name??
the static variable keep the orginal values,why?