Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Doubt regarding threads

 
Ranch Hand
Posts: 37
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
In a practice exam from web site examlab.tk, i have encountered the following question



The output of the program was asked, the options given were


1. A:0 A:1 A:2 A:3 B:0 B:1 B:2 B3
2. B:1 A:1 A:2 B:3 A:3 B:2 A:4 B:4
3. B:1 B:2 A:1 B:3 A:2 A:3 B:4 A:4
4. A:2 B:1 B:2 B:3 A:3 A:4 B:4 A:1
5: A:1 A:2 A:3 B:1 A:4 B:2 B:3 B:4


The Answer i have kept was 2 and 3 but the answer which was given was 3 and 5

i am unable to understand how?
how the swapping of the threads found out in runtime, according to the SCJP 6 book, it is said that

it is difficult to predict the thread execution at runtime,

can someone please shed some light on this?


Regards,
Siddartha
 
Ranch Hand
Posts: 449
Scala IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please Quote Your Source first.
 
Ranch Hand
Posts: 178
2
Netbeans IDE MySQL Database Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is not difficult, actually you can't predict the thread execution at runtime. But here, the question is actually not about thread. It is about for loop..

Answer 1: Wrong. A:0 cannot be printed as for loop is running from 1 to 4.

Answer 2: Wrong. B:2 is printed here after printing B:3. That will not happen.

Answer 3: Correct.

Answer 4: Wrong. A:1 is printed at last. and that also cannot be happened.

Answer 5: Correct.
 
Siddarth Cherukumudi
Ranch Hand
Posts: 37
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@ Ramesh

Thats so dumb of me, not understanding the question...

thanks a lot for pointing the problem, i owe you big time..
 
this is supposed to be a surprise, but it smells like a tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic