JDK-8297962 review ?

Stanimir Stamenkov stanio at yahoo.com
Tue Jan 28 20:19:08 UTC 2025


Tue, 28 Jan 2025 11:32:41 -0800, /Philip Race/:

> why would the state change never happens / gets lost ?

Is it possible the state changes after the 'if', and before the lock is 
obtained?

         if (peer.getState() != state) {
             synchronized (lock) {

Maybe the the 'if' test should be re-evaluated inside the synchronized 
block, first or maybe using a CountDownLatch is more suitable:

         CountDownLatch latch = new CountDownLatch(1);
         WindowStateListener wsl = new WindowStateListener() {
             public void windowStateChanged(WindowEvent e) {
                 if (e.getNewState() == state) {
                     latch.countDown();
                 }
             }
         };

         target.addWindowStateListener(wsl);
         for (int retries = 5; retries > 0
                 && peer.getState() != state; retries--) {
             try {
                 latch.await(1, TimeUnit.SECONDS);
             } catch (InterruptedException ie) {
                 Thread.currentThread().interrupt();
                 break;
             }
         }
         target.removeWindowStateListener(wsl);

> The code wants a specific state (NORMAL). What if the window is 
> transitioned to some other state instead ?
> So there's a couple of possibilities.

-- 


More information about the client-libs-dev mailing list