On Wed, 10 Sep 2025 00:23:47 GMT, Sergey Bylokhov <[email protected]> wrote:

> think we should recheck whether new methods like this one need to be 
> synchronized. Some time ago, the synchronized keyword was removed from the 
> delay method because synchronization could cause the delay to last longer 
> than intended and unnecessarily block other methods.
> 
> In this case, waitForIdle() might be in a synchronized block (but the method 
> itself is already synchronized), but do we really want to call delay() while 
> holding the lock?

I expect you are referring to this fix you did about 6 years ago 
https://bugs.openjdk.org/browse/JDK-8210231 ?

That bug was more about side-effects of delay but ended up removing 
synchronized.

> 3. "synchronized" keyword was removed, because of this bug: "if two threads 
> call delay(1000) at around the same time then one of them will be a delay for 
> 2000ms". 

I'm not sure that ever affected any actual tests since Robot usage should be 
single threaded in all usual cases.

I can just about see a case for removing synchronized from the 
waitForIdle(delay) method - because waitForIdle() is already synchronized
and delay() doesn't change anything
But for cases like type() it is important for its operation that only one 
thread be allowed.
Just imagine the havoc if there are N robots all concurrently typing away - 
that's what is allowed by removing synchronized.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/26969#discussion_r2349918664

Reply via email to