Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubt on start and run methods

 
Charu Murali
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • 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
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Overriding start() is legal but is almost certainly a programming error.
 
Sun LiWei
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • 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.
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • 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).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic