• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

what's the use of start()?

 
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this program runs....
class th implements Runnable{
public static void main(String args[]){
Thread t = new Thread(new th());
t.run();
}
public void run(){
for (int i = 1; i<11; i++){
System.out.println("Count is " + i);
try {
Thread.sleep(1000);} catch (InterruptedException e){}
}
}
}

so why do we use start()?
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
while you do this
t.run()
there is nothing wrong with that. but what you infact do is you fire the method to be executed. But it's not a thread that get's the work done for you. At least not the one that you are thinking is running right now. The code runs and prints whatever you have there. But what does the work is the thread that runs your applet in a browser. So the start() method makes the thread to run . the thread that you created.
 
Anshuman Acharya
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
got it, thanx
reply
    Bookmark Topic Watch Topic
  • New Topic