About Question enthuware.ocpjp.v7.2.1087 :

Moderator: admin

Post Reply
dieterdde
Posts: 19
Joined: Wed May 25, 2016 4:33 am
Contact:

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

Post by dieterdde » Wed Jun 15, 2016 9:52 am

Hello,

whilst I took the right answer for lack of any better answer, I'm really puzzled why it's the right answer, again it may be semantics but, I don't believe it's correct to state that add/remove operations can happen simulteanously even if you toss in the word "safely" in there, doesn't mean it's simultaneous. Reason: CopyOnWriteArrayList will block simultaneous write attempts (uses a ReentrantLock internally), without blocking reads (which is it's main advantage over a ReentrantReadWriteLock).

It would be right to say that multiple threads can "attempt" simultaneous add/remove operations, but they don't actually "happen" simultaneous, right?

This question drove me nuts, I finished the test with 10 minutes to spare and spent it in full on this question, as none of the answers were truly correction my opinion. The 3rd potential answer got it right that you can't add simultaneously, but said "can't do it in a thread safe manner" which is also not correct as CopyOnWriteArrayList is of course thread safe.

As you can tell from my previous posts, I REALLY struggle sometimes with wordings! Is the exam also as tricky like that in wording? It's gonna be a nightmare for me.

Luckily it was the only question that drove me nuts, so I did get 100% on the test 11 on Concurrency. Phew. Onto chapter 12 on Localization!

Cheers

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

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

Post by admin » Wed Jun 15, 2016 10:27 am

I am not sure what is your reference point when you think of the word simultaneous. If you look at it from a CPU level, nothing is simultaneous in a single core machine. After all, the CPU can execute only one instruction at a time.
But if you look at it from the OS level, you can indeed say that there are multiple threads that are doing something simultaneously.

In this question and also in general, when you talking about simultaneous execution of threads, you talk from the JVM's perspective. It manages multiple threads and executes them simultaneously (now, whether it is an illusion using time slicing or real concurrent execution is a different issue.) So here, it is ok to say multiple threads can read and write to the data structure simultaneously. All it means is that one thread doesn't have to synchronize its operation with another thread before modifying the shared data structure. If multiple threads don't synchronize, then obviously, you are accepting the possibility that they can both try to modify it at the same time.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

jagoneye
Posts: 97
Joined: Wed Dec 28, 2016 9:00 am
Contact:

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

Post by jagoneye » Wed Jan 11, 2017 2:23 pm

It would be helpful if provided which Collection allows null key/value insertions and which not including those in the concurrent package as well.

nowkarol
Posts: 5
Joined: Sun Aug 05, 2018 5:41 am
Contact:

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

Post by nowkarol » Sun Aug 05, 2018 5:47 am

So here, it is ok to say multiple threads can read and write to the data structure simultaneously
I think no. If yes then we can say that Collections.synchronizedList allow to write and read data simultaneously. It is internally synchronized. Same as CopyOnWriteArrayList - it is internally synchronized while copying internal array. So two threads are not allowed to modify it in same time. But critical section is narrowed only to copying array operation.

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

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

Post by admin » Sun Aug 05, 2018 6:10 am

You are taking a statement out of context. Please read the whole post in its entirely. "simultaneous access" always depends on the perspective. From the application perspective everything may happen simultaneously while from a CPU perspective everything happens sequentially. Now, in the middle these two ends, some parts may appear to happen simultaneously while some may not. That depends on which side of the things you are on.
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 11 guests