Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Review Question #22 (Chapter 18) (Sybex CSG 11 p. 910 Kindle Edition)

 
Ranch Hand
Posts: 41
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I executed the code from question 22, I got the following output:

100 100

And the supposedly correct answer is B:

The method consistently prints 100 100.

(Boyarsky, Jeanne; Selikoff, Scott. OCP Oracle Certified Professional Java SE 11 Developer Complete Study Guide (p. 909). Wiley. Kindle Edition.)

Perhaps I don't understand the meaning of the word consistently, my Kindle tells me that it is: in every case or on every occasion.

But the output is only displayed once, it is not repeated, so "consistently" is confusing here.
Also, the question is not stating that the code is executed more than once, and in other review questions that always meant it is executed once.
 
Marshal
Posts: 71682
312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please supply more details about the question for those of us who don't have the book. The bit about consistently means you will always get the result

100 100

every time, irrespective of how many times you run the program.
 
Rade Koncar
Ranch Hand
Posts: 41
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Assuming 100 milliseconds is enough time for the tasks submitted to the service executor to complete, what is the result of executing the following method? (Choose all that apply.)  



   A The method consistently prints 100 99.
   B The method consistently prints 100 100.
   C The output cannot be determined ahead of time.
   D The code will not compile because of line w1.
   E The code will not compile because of line w2.
   F The code will not compile because of line w3.
   G It compiles but throws an exception at runtime.


Yes, I guess you could interpret it like that, irrespective of how many times you run the program, meaning the code is executed more than once (every time as part of another process).

Thanks.
 
Campbell Ritchie
Marshal
Posts: 71682
312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Single thread executor? Doesn't that mean you are running a single thread, so there won't be any synchronisation issues? You can see that both the int and the AtomicInteger object are always incremented 100×. You will see that the shutdown() method allows all tasks to complete.

There seems to be a discrepancy in the ExecutorService documentation. It says at the top that,

. . . The shutdown() method will allow previously submitted tasks to execute before terminating . . . ,

but the link I posted a few lines above disagrees with that. Which part have I read wrongly?
 
Friends help you move. Good friends help you move bodies. This tiny ad will help:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic