File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes run() method in thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "run() method in thread" Watch "run() method in thread" New topic

run() method in thread

Bijesh Krishnadas
Ranch Hand

Joined: Aug 08, 2002
Posts: 31
somebody plzzz answer this....
Does the Thread class define the run() method? i.e. the run() method is not abstract in Thread class.
Anthony Villanueva
Ranch Hand

Joined: Mar 22, 2002
Posts: 1055
The Thread class's run() method does nothing. According to the docs:

If this thread was constructed using a separate Runnable run object, then that Runnable object's run method is called; otherwise, this method does nothing and returns.
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

But that's not 'nothing'.
If you pass the Thread a Runnable object it will start it up ie

as per the second example in the javadocs, otherwise it will do nothing and end.
It does sit there nicely for you to override when you extend the Thread class though...
Peter Kristensson
Ranch Hand

Joined: Jul 02, 2001
Posts: 118
note the difference between the run() and start() method.
the run() method locks the current thread, but the start() method returns directly after firing the new thread.
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Bijesh K,
Welcome to JavaRanch!
We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.
Thanks Pardner! Hope to see you 'round the Ranch!

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Bijesh Krishnadas
Ranch Hand

Joined: Aug 08, 2002
Posts: 31
thanx 4 the help ppl!
I agree. Here's the link:
subject: run() method in thread
It's not a secret anymore!