Object-based monitors vs Lock based-monitors for JDK 17+
Pedro Felix via Concurrency-interest <[email protected]> Wed, 29 Sep 2021 17:50:40 +0100
| Newsgroups | gmane.comp.java.jsr.166-concurrency |
|---|---|
| Message-ID | <CAD+AFDtvZSjYSSWaqO5VO-OS6Oh3_6B2mMSFir7Qzvh8GTYhMg@mail.gmail.com> |
--===============8027626462047678639== Content-Type: multipart/alternative; boundary="000000000000026b0805cd252225" --000000000000026b0805cd252225 Content-Type: text/plain; charset="UTF-8" Hi, What are the recommendations on the use of Object-based monitors (i.e. synchronized, Object.wait, Object.notify) vs. the use of Lock-based monitors (i.e. Lock and Monitor interfaces), for JDK 17 and upcoming versions? There are scenarios where the Lock-based monitors are clearly preferable, such as needing more than one condition or having non-structured lock-unlock pairs. However, for simple scenarios where both are applicable, which should we use? Are there any performance or other advantages in using Object-based vs. Lock-based monitors? Also, which are preferable when using Loom's virtual threads? I recall reading that there may be limitations around Object-based monitors and virtual threads, such as blocking the carrier thread. Thanks. Regards, Pedro --000000000000026b0805cd252225 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">Hi,<div><br></div><div>What are the recommendations=C2=A0o= n the use of Object-based monitors (i.e. synchronized, Object.wait, Object.= notify) vs. the use of Lock-based monitors (i.e. Lock and Monitor interface= s), for JDK 17 and upcoming versions?</div><div>There are scenarios where t= he Lock-based monitors are clearly preferable, such as needing more than on= e condition or having non-structured lock-unlock pairs.</div><div>However, = for simple scenarios where both are applicable, which should we use? Are th= ere any performance=C2=A0or other advantages in using Object-based vs. Lock= -based monitors?</div><div>=C2=A0</div><div>Also, which are preferable when= using Loom's virtual threads? I recall reading that there may be limit= ations around Object-based monitors and virtual threads, such as blocking t= he carrier thread.</div><div><br></div><div>Thanks.</div><div>Regards,</div= ><div>Pedro</div></div> --000000000000026b0805cd252225-- --===============8027626462047678639== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Concurrency-interest mailing list [email protected] http://cs.oswego.edu/mailman/listinfo/concurrency-interest --===============8027626462047678639==--