cactoos icon indicating copy to clipboard operation
cactoos copied to clipboard

reentrant lock

Open l3r8yJ opened this issue 1 year ago • 3 comments

closes #1688

@fabriciofx take a look, please

l3r8yJ avatar Aug 20 '23 19:08 l3r8yJ

@l3r8yJ

please, change the constructors to something like this:

public Synced(final Scalar<? extends T> scalar) {
   this(scalar, new ReetrantLock());
}

public Synced(final Scalar<? extends T> scalar, final ReentrantLock lock) {
   this.origin = scalar;
   this.lock = lock;
}

(and the same to Synced in Text.

Another thing: can you provide a Test to measure the performance improvement (because now is parallel)?

fabriciofx avatar Aug 21 '23 03:08 fabriciofx

Hello @l3r8yJ, what is the advantage of using this over the synchronized keyword? synchronized and reentrant locks are exactly the same semantically as far as I know.

The only difference is when using the new Java 21 virtual threads which does not support (yet) the synchronized keyword.

More details here: https://stackoverflow.com/a/11821900

victornoel avatar Aug 21 '23 08:08 victornoel

@fabriciofx what's the point of these ktors? I don't see the point of this design.

can you explain, please?

l3r8yJ avatar Aug 21 '23 14:08 l3r8yJ