This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Threads" Watch "Threads" New topic


Ranch Hand

Joined: Aug 03, 2000
Posts: 169
public class Whiffler extends Object implements Runnable {
2. Thread myT ;
3. public void start(){
4. myT = new Thread( this );
5. }
6. public void run(){
7. while( true ){
8. doStuff();
9. }
10. System.out.println("Exiting run");
11. }
12. // more class code
Assume that the rest of the class defines doStuff, etc and that the class compiles without error. Also assume that a Java application creates a Whiffler object and calls the Whiffler start method, that no other direct calls to Whiffler methods are made an that the Thread in this object is the only one the application creates. Which of the following are correct statements ?
In this case why is the doStuff() never executed??
- Thanks
deekasha gunwant
Ranch Hand

Joined: May 06, 2000
Posts: 396
Hi Doit,
u must be wondering that since start method is supposed to call the run method so ur doStuf() method must get executed.
actually u r confusing the start() method of class Thread with the method defined in ur own class.
if u remember It's the start() method of Thread class that calls run method on its own. in ur case a thread is created using
myT = new Thread( this );
but since u r not calling myT.start() so ur run method never gets called.

Ranch Hand

Joined: Aug 03, 2000
Posts: 169
Thanks. I missed the point.
I agree. Here's the link:
subject: Threads
It's not a secret anymore!