Forums Register Login

doubt on start and run methods

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
Overriding start() is legal but is almost certainly a programming error.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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).
Police line, do not cross. Well, this tiny ad can go through:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 672 times.
Similar Threads
Question on Thread
thread
Doubt in Thread run method.
Marcus Green mock exam 1, Q.31.
Marcus Green mock exam 1 question 31????
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 00:52:42.