yegor256 / cactoos

Object-Oriented Java primitives, as an alternative to Google Guava and Apache Commons
https://www.cactoos.org
MIT License
734 stars 162 forks source link

reentrant lock #1689

Open l3r8yJ opened 11 months ago

l3r8yJ commented 11 months ago

closes #1688

@fabriciofx take a look, please

fabriciofx commented 11 months ago

@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)?

victornoel commented 11 months ago

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

l3r8yJ commented 11 months ago

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

can you explain, please?