• 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

doubt on start and run methods

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Is there any difference between overriding a start method and overriding a run method? In Marcus Green Exam#3, there was a qn.. like

And the answer is 3. (ie) first0, first1, second0, second1.

In the explanation it was given as, if we want to get mixed up reslts like first0, second1... we should have overridden the run() method.
Can any one explain me.

Thanks
Charu
 
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Overriding start() is legal but is almost certainly a programming error.
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if you try this piece of code:


public class C extends Thread
{
public void run()
{
System.out.println("Thread run");
}
public void start()
{
}
public static void main(String args[])
{
new C().start();
}
};


you will see nothing being outputted,because the start() method is overridden and the Class C can't run as a thread.So if you overridden the start() method,you can't make your class run as Thread.
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The start method should not be overridden unless you are providing your own native thread scheduler which I doubt. When invoking start on your thread, the latter is scheduled for execution by the underlying scheduler. When your thread is given the permission to execute, the content of its run method will be executed. That's why you have to override the run method in order to provide your own behavior (the default is empty).
reply
    Bookmark Topic Watch Topic
  • New Topic