Re: Best Practice for Busy Waiting in Java

2025-06-17 Thread Markus KARG
re-libs-dev on behalf of Alan Bateman *Sent:* Monday, 16 June 2025 17:23 *To:* Markus KARG *Cc:* core-libs-dev *Subject:* Re: Best Practice for Busy Waiting in Java On 16/06/2025 12:09, Markus KARG wrote: > > > In case you MUST use busy-wait, apply the following rules: > > > * N

Re: Best Practice for Busy Waiting in Java

2025-06-17 Thread Viktor Klang
KARG Cc: core-libs-dev Subject: Re: Best Practice for Busy Waiting in Java On 16/06/2025 12:09, Markus KARG wrote: > > > In case you MUST use busy-wait, apply the following rules: > > > * NEVER have EMPTY busy-wait loops, but ALWAYS put Thread.onSpinWait() > into it. The perfor

Re: Best Practice for Busy Waiting in Java

2025-06-16 Thread Alan Bateman
On 16/06/2025 12:09, Markus KARG wrote: In case you MUST use busy-wait, apply the following rules: * NEVER have EMPTY busy-wait loops, but ALWAYS put Thread.onSpinWait() into it. The performance drop is negligible but the CO2 footprint is considerably smaller. * IF it is acceptable for th

Re: Best Practice for Busy Waiting in Java

2025-06-16 Thread Markus KARG
5, 2025 10:42 PM *To:* Markus KARG ; Archie Cobbs *Cc:* core-libs-dev *Subject:* Re: Best Practice for Busy Waiting in Java Not a concurrency professional, but my first impression is whether to yield or spin depends on how costly the task you are waiting is - I know yield involves a conte

Re: Best Practice for Busy Waiting in Java

2025-06-16 Thread Per-Ake Minborg
are a good choice in this domain. Best, Per Minborg From: core-libs-dev on behalf of Chen Liang Sent: Sunday, June 15, 2025 10:42 PM To: Markus KARG ; Archie Cobbs Cc: core-libs-dev Subject: Re: Best Practice for Busy Waiting in Java Not a concurrency

Re: Best Practice for Busy Waiting in Java

2025-06-15 Thread Chen Liang
Cobbs Cc: core-libs-dev Subject: Re: Best Practice for Busy Waiting in Java Seems you misunderstood my question. It was *not* what is best to do. It was: "Does the core-libs team have a common-sense / best practice for busy-wait.". The latter is a clear and concise question, and the an

Re: Best Practice for Busy Waiting in Java

2025-06-15 Thread Markus KARG
Seems you misunderstood my question. It was *not* what is best to do. It was: "Does the core-libs team have a common-sense / best practice for busy-wait.". The latter is a clear and concise question, and the answer could be as simple as "yes" or "no". Am 15.06.2025 um 18:40 schrieb Archie Cobb

Re: Best Practice for Busy Waiting in Java

2025-06-15 Thread Archie Cobbs
Just MHO... This is kind of like asking "What's the best way to waste electricity?" It's a nebulous question until you specify what "best" means in this odd scenario -Archie On Sun, Jun 15, 2025 at 11:09 AM Markus KARG wrote: > Recently I was asked by a programmer, what to do if there sim

Best Practice for Busy Waiting in Java

2025-06-15 Thread Markus KARG
Recently I was asked by a programmer, what to do if there simply is no other way than actually busy-wait. I see several options: * Do nothing: Costs valuable CPU time and increases carbon footprint. * Do a power-nap: Thread.sleep(1) * Be fair: Thread.yield() gives other threads a chance to ex