File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Threads" Watch "Threads" New topic
Author

Threads

Doit
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.


regards
deekasha
Doit
Ranch Hand

Joined: Aug 03, 2000
Posts: 169
Thanks. I missed the point.
 
 
subject: Threads