About Question enthuware.ocpjp.v7.2.1438 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
danidark9312
Posts: 4
Joined: Tue Jul 10, 2018 5:28 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1438 :

Post by danidark9312 »

admin wrote:
Wed Jul 11, 2018 9:30 pm
There is a huge difference between the two codes. In the code of this question (2.1438), the variable sorted is always accessed from within a synchronized block, whereas in question 2.1558, the variable threadCounter is not accessed from a synchronized block.

For a thread to be able to see modifications to a variable done by other threads, either the variable must be volatile or the the threads must access the variable from within a synchronized block.
You need to read about "Java Memory Model" (just google it) from a good book. Even oracle's official Java tutorial is a good start. If the book that you are reading doesn't explain this fundamental concept then I will not recommend that book.

HTH,
Paul.
Thank you Paul for replying.

I've googled the concept of "Java Memory Model", but for me that's nothing to do with concurrency, in top of that I'm quite sure those topics about java memory model are not being included in the exam, even in the exam topics at the oracle certified website is not included that concept.

Also before I made the question in this forum I checked the specs about concurrency and syncronized blocks, also the definition of a volatile variable, multiple times and I still couldn't find anything abount this case.

Btw this is my book: learning java. patrick niemeyer daniel leuck 4th edition Java 7

admin
Site Admin
Posts: 10046
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v7.2.1438 :

Post by admin »

Not sure what article you read, but you may start here: http://tutorials.jenkov.com/java-concur ... model.html
If the book that you are reading doesn't explain volatile and synchronized, I suggest you use another book.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 85 guests