• 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
  • Liutauras Vilda
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Peter Rooke
  • Himai Minh
Bartenders:
  • Piet Souris
  • Mikalai Zaikin

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: 41656
883
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: 4335
39
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.
reply
    Bookmark Topic Watch Topic
  • New Topic