It's not a secret anymore!
The moose likes Beginning Java and the fly likes Why this does not fail? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Why this does not fail?" Watch "Why this does not fail?" New topic
Author

Why this does not fail?

Brian Smith
Ranch Hand

Joined: Oct 26, 2002
Posts: 232
hi folks,

i thought the program would fail compiling as we can not invoke run()method directly. but it works fine. WHY?
I would appreciate if someone explains me.
thanks.
[ July 29, 2003: Message edited by: Namaste Sathi ]
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1815
There's nothing preventing you from calling run: it is delared as public. The Thread class's run method does nothing (unless it was created with a Runnable object); but in your subclass here, it does do something.


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Brian Smith
Ranch Hand

Joined: Oct 26, 2002
Posts: 232
Joel,
so it's not necessary true that we can't invoke run() method of a Thread directly. And also, we can't predict when the run()method gets excuted once the start() is invoked. right?
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
If you invoke the run() method then it is not running as a separate thread. run() is no different than any other method when invoked that way.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Why this does not fail?
 
Similar Threads
About thread
Doubt in Thread output
Problem in thread
Thread Doubt
run() method