Page 1 of 1

About Question enthuware.ocpjp.v7.2.1138 :

Posted: Fri Feb 13, 2015 12:11 pm
by ewebxml
Does the ReadWriteLock presented in the explanation offer a more modern solution to the problem?

Although this question asked about synchronization within the context of traditional threads,
a solution to the problem could be to use a more modern approach using the
concurrent package.

The ReadWriteLock from the concurrent package requires the following imports:

Code: Select all

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

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

Posted: Fri Feb 13, 2015 10:13 pm
by admin
Yes, it is a modern and recommended approach.

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

Posted: Wed Jul 20, 2022 2:58 pm
by ftejada
I was wondering whether CopyOnWriteArrayList could be a valid alternative as it internally uses a ReentrantLock in the add method:

- OpenJDK 8: https://hg.openjdk.java.net/jdk8u/jdk8u ... .java#l433

However, something that caught my attention was the fact that the OpenJDK 17 implementation no longer uses ReentrantLock (there is a comment from the maintainer stating that they prefer builtin monitors over ReentrantLock :mrgreen: )
- OpenJDK 17:https://github.com/openjdk/jdk17/blob/m ... .java#L429

Anyway, regardless of the CopyOnWriteArrayList implementation, would that be a valid option to the question? (Excluding the fact that it would no longer be an ArrayList<String> but a CopyOnWriteArrayList<String>).

Thanks.

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

Posted: Fri Jul 22, 2022 7:08 am
by admin
Yes, using CopyOnWriteArrayList is also a valid approach. As per its JavaDoc API description, "it is useful when you cannot or don't want to synchronize traversals, yet need to preclude interference among concurrent threads.", which suits very well for the given situation.

The solution in the explanation is to show the concept behind preventing multiple reads and writes from interfering/corrupting the collection. Using CopyOnWriteArrayList in the example would not show what goes behind the scene. It is a blackbox that you can just use without worrying about multithreading issues.

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

Posted: Thu Jul 28, 2022 11:25 am
by marcoolivi
Is that part of the 1Z0-829 program?

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

Posted: Thu Jul 28, 2022 12:08 pm
by admin
Yes, Locks are part of 829.

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

Posted: Wed Oct 04, 2023 4:24 pm
by gurban.azimli
I could not see anything about ReadWriteLock in OCP Study Guide for exam 1z0-829.
Are you sure that ReadWriteLock is the topic of the exam?

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

Posted: Fri Oct 06, 2023 3:47 am
by admin
Yes, it is on the exam.
Many people have reported that the said book does not cover many things that they got on the exam.