• 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

Thread Answer Error

 
Ranch Hand
Posts: 384
MyEclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This question is from Practice Exam book form K & B.



Given Anser in book
t. yield() and t.join()will make most (or all) of Loop #2’s iterations
run before most (or all) of Loop #1’s iterations?

When I tried out it
t.join() is good But t.yield() is not.
 
author
Posts: 23919
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

naveen yadav wrote:When I tried out it
t.join() is good But t.yield() is not.



Look up the join() and the yield() method. And see if you can figure out why the join() method works here, and the yield() method does not.

It's pretty easy. Look into it a bit.


Or is the point of this question to confirm the error? In which case, I agree with you...
Henry
 
naveen yadav
Ranch Hand
Posts: 384
MyEclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes I want to confirm about the error in the ANSWER CHOICE which says "join() and yield BOTH will produce required output".
but in Real World Only join() will work whereas yield will not produce desired output.

Agree??
 
Ranch Hand
Posts: 37
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why can't t1.yield() be chosen? Below is from Java 6 API for Thread.yield():
"public static void yield(): Causes the currently executing thread object to temporarily pause and allow other threads to execute."

I think yield() will cause current main thread to pause and gives t1 a chance to run.
 
There’s no place like 127.0.0.1. But I'll always remember this 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