Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Master exam Thread question

 
Biby Thoms
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am always getting Stimpy 100 times for all excution.

But exam reference saying the output for the following question is Ren Ren Ren...Stimpy Stimpy Stimpy

 
Zhu Ho
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The thread for InnerRun never start so it won't be run. So only InnerRunTwo is run.
 
Shailesh Kumar
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure if it wasn't like this?


InnerRun ir = new InnerRun();
Thread t = new Thread(ir);//ir is passed here in the constructor


May be a printing mistake.
 
Dave Reinhardt
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unless this is a possible answer, I think there is a bug in the following code sample:

void start() {
InnerRun ir = new InnerRun();
Thread t = new Thread(ir); //wasn't passed the runnable ir
InnerRunTwo irr = new InnerRunTwo(t);
Thread uu = new Thread(irr);
t.start();
uu.start();
}

If you make this change then you will get 100 Ren and then 100 Stimpy. As it was in the original code, the thead t wasn't given a job(a runnable) to do.
 
Biby Thoms
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are correct Shail...Good catch. Thank you all
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic