Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Threads

 
Doit
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 396
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. I missed the point.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic