• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help me Thread

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1> How does system(or compiler) calls run() method when we call start() method???
My guess is start() method is run() method from inside like this
public static void start(){
run();
}

Is start() method implemented the same way as i have written above ???
2> When we give our own implementation of start() method in class one which extends Thread class and another which implements Runnable interface.

After instantiating thread th1, when we call th1.start() then it is calling our own start() method for the class which extends Thread Class
but same is not true for the class which implements Runnable interface.

Please explain the above bizzarre behaviour.
Thanks
 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1.start() method is not directly calling run(). If that is the case, then the run will execute immediately. start is invoking a native method to communicate with the scheduler and the scheduler will inturn calls the run method, when the new thread get a chance to execute the CPU.

2.When we extend Thread class and provide implementation for the start() method, we are overriding the start() method of the Thread class. So our start() will get execute.

In the case of implementing runnable, you are not overriding the start() method of the Thread class.
Could you please send your code ?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic