• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Master exam Thread question

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The thread for InnerRun never start so it won't be run. So only InnerRunTwo is run.
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are correct Shail...Good catch. Thank you all
 
reply
    Bookmark Topic Watch Topic
  • New Topic