About Question enthuware.ocpjp.v7.2.1138 :

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

Moderator: admin

Post Reply
ewebxml
Posts: 78
Joined: Sun Jun 30, 2013 10:04 pm
Contact:

About Question enthuware.ocpjp.v7.2.1138 :

Post 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;

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

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

Post by admin »

Yes, it is a modern and recommended approach.
If you like our products and services, please help us by posting your review here.

ftejada
Posts: 5
Joined: Mon Jan 28, 2019 2:00 pm
Contact:

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

Post 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.

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

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

Post 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.
If you like our products and services, please help us by posting your review here.

marcoolivi
Posts: 4
Joined: Wed Jul 27, 2022 7:35 am
Contact:

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

Post by marcoolivi »

Is that part of the 1Z0-829 program?

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

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

Post by admin »

Yes, Locks are part of 829.
If you like our products and services, please help us by posting your review here.

gurban.azimli
Posts: 3
Joined: Wed Oct 04, 2023 2:56 pm
Contact:

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

Post 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?

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

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

Post 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.
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 57 guests