Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Sybex CSG 11, Chapter 18, Review Question 22. pages 909 and 1165

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. In the explanation (page 1165) variable sheepCount2 is mentioned, but in the review question(page 909) that variable is called simply s2.

2. I don't understand how the behaviour described in correct answer is guarantied by java.
I found out that this question was in OCP Java 8 Study Guide, and 4 years ago Andrzej Czarny argued that output cannot be determined ahead of time. There is a discussion:  https://coderanch.com/t/684463/certification/Sybex-OCP-Java-Study-Guide , but I don't see that discussion as complete.

Scott Selikoff answered that "Assuming 100 milliseconds is enough time for the tasks submitted to the thread executor to complete" covers the case, but I think, that there is no time that can guarantee that main thread will see the changes from executor's thread without proper synchronisation. Main thread may never ever see any changes and may continue reading s2 from it's own cache an be confident that it's value is 0. Or some other value in between 0 and 100.

Could you please review this question and discussion with Andrzej Czarny once again?
 
author & internet detective
Posts: 40913
840
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1) Agreed and I've added to the errata

2) I agree with Scott. 100ms is plenty for the tiny amount of work being done there
 
author
Posts: 4281
34
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For #2, it's guaranteed because the question says it is enough time.  The question text isn't asking you if 100ms is enough time, it's telling you it is.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic