• Post Reply Bookmark Topic Watch Topic
  • New Topic

Sybex OCA OCP Practice Test online Chapter 19 Q.23  RSS feed

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

First of all I would like to thank you for the great job with OCA/OCP Java SE8 Programmer Practive Tests Book!

I tried the code in Sybex OCA OCP Practice Test online Chapter 19 Q.23 with: "static int count=0;".



And as explained in the answer : If count was marked static, then the application would sum the elements correctly, printing 10. Indeed, it prints 10 correctly.
My question is: Why is it not needed to declare count as Atomic variable?
As more threads are working with count concurrently, I thought it would be necessary in order to keep consistency.

Please help me to understand!

Thanks

 
Zanna Bianca
Greenhorn
Posts: 9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi again,
I tried the same code with a big array (lenght=1000) and the result was that it is needed an Atomic variable, otherwise you can have not the right sum
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!