<div dir="auto">Hi,<div dir="auto"><br></div><div dir="auto">My main concerns consists in avoiding any deadlock due to appkit (main thread), EDT, flusher & disposer + user threads...</div><div dir="auto"><br></div><div dir="auto">Instead of new lock.wait(), why not rely on other existing patterns like LWCToolkit.invokeAndWait() ?</div><div dir="auto">It implements non-blocking rendez-vous to avoid appkit or EDT threads to wait but perform other pending events meanwhile.</div><div dir="auto"><br></div><div dir="auto">More details later,</div><div dir="auto">Laurent</div></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">Le mar. 28 janv. 2025, 21:19, Stanimir Stamenkov <<a href="mailto:stanio@yahoo.com">stanio@yahoo.com</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Tue, 28 Jan 2025 11:32:41 -0800, /Philip Race/:<br>
<br>
> why would the state change never happens / gets lost ?<br>
<br>
Is it possible the state changes after the 'if', and before the lock is <br>
obtained?<br>
<br>
if (peer.getState() != state) {<br>
synchronized (lock) {<br>
<br>
Maybe the the 'if' test should be re-evaluated inside the synchronized <br>
block, first or maybe using a CountDownLatch is more suitable:<br>
<br>
CountDownLatch latch = new CountDownLatch(1);<br>
WindowStateListener wsl = new WindowStateListener() {<br>
public void windowStateChanged(WindowEvent e) {<br>
if (e.getNewState() == state) {<br>
latch.countDown();<br>
}<br>
}<br>
};<br>
<br>
target.addWindowStateListener(wsl);<br>
for (int retries = 5; retries > 0<br>
&& peer.getState() != state; retries--) {<br>
try {<br>
latch.await(1, TimeUnit.SECONDS);<br>
} catch (InterruptedException ie) {<br>
Thread.currentThread().interrupt();<br>
break;<br>
}<br>
}<br>
target.removeWindowStateListener(wsl);<br>
<br>
> The code wants a specific state (NORMAL). What if the window is <br>
> transitioned to some other state instead ?<br>
> So there's a couple of possibilities.<br>
<br>
-- <br>
</blockquote></div>