This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes doubt on start and run methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "doubt on start and run methods " Watch "doubt on start and run methods " New topic

doubt on start and run methods

Charu Murali
Ranch Hand

Joined: Jul 12, 2002
Posts: 37
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.

Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
Overriding start() is legal but is almost certainly a programming error.

Ron Newman - SCJP 1.2 (100%, 7 August 2002)
Sun LiWei
Ranch Hand

Joined: Aug 10, 2002
Posts: 49
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

Joined: Aug 26, 2001
Posts: 7610
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).

[Blog] [Blogroll] [My Reviews] My Linked In
I agree. Here's the link:
subject: doubt on start and run methods
It's not a secret anymore!