You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by jt...@apache.org on 2020/12/26 14:40:14 UTC

[netbeans-html4j] 19/25: Don't hold a reference to item when scheduling pending check

This is an automated email from the ASF dual-hosted git repository.

jtulach pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans-html4j.git

commit 627e73b93a71b01848f0f9c1b69793c99d9e7a79
Author: Jaroslav Tulach <ja...@apidesign.org>
AuthorDate: Thu Dec 24 08:13:28 2020 +0100

    Don't hold a reference to item when scheduling pending check
---
 .../org/netbeans/html/presenters/spi/Generic.java  | 41 ++++++++++++----------
 1 file changed, 23 insertions(+), 18 deletions(-)

diff --git a/generic/src/main/java/org/netbeans/html/presenters/spi/Generic.java b/generic/src/main/java/org/netbeans/html/presenters/spi/Generic.java
index 3204355..1da8eb7 100644
--- a/generic/src/main/java/org/netbeans/html/presenters/spi/Generic.java
+++ b/generic/src/main/java/org/netbeans/html/presenters/spi/Generic.java
@@ -509,7 +509,7 @@ abstract class Generic implements Fn.Presenter, Fn.KeepAlive, Flushable {
         void callbackReady(String name);
     }
     
-    private class Item implements Runnable {
+    private class Item {
         final int id;
         final Item prev;
         Boolean done;
@@ -554,15 +554,6 @@ abstract class Generic implements Fn.Presenter, Fn.KeepAlive, Flushable {
             }
         }
         
-        @Override public void run() {
-            synchronized (lock()) {
-                log(Level.FINE, "run: {0}", this);
-                inJava();
-                lock().notifyAll();
-            }
-        }
-        
-
         protected String js(boolean[] finished) {
             if (Boolean.TRUE.equals(done)) {
                 StringBuilder sb = new StringBuilder();
@@ -683,14 +674,9 @@ abstract class Generic implements Fn.Presenter, Fn.KeepAlive, Flushable {
                     return def.toString();
                 }
                 finished[0] = false;
-                final Item top = topMostCall();
-                if (top.method != null) {
-                    if (top.done == null) {
-                        dispatch(top);
-                        if (getDeferred(false) != null) {
-                            continue;
-                        }
-                    }
+                final Item top = dispatchPendingItem();
+                if (top == null) {
+                    continue;
                 }
                 String jsToExec = top.inJavaScript(finished);
                 log(Level.FINE, "jr: {0} jsToExec: {1} finished: {2}", new Object[]{topMostCall(), jsToExec, finished[0]});
@@ -705,6 +691,25 @@ abstract class Generic implements Fn.Presenter, Fn.KeepAlive, Flushable {
         }
     }
 
+    private Item dispatchPendingItem() {
+        final Item top = topMostCall();
+        if (top.method != null && top.done == null) {
+            dispatch(() -> {
+                synchronized (lock()) {
+                    Item pending = topMostCall();
+                    if (pending != null) {
+                        pending.inJava();
+                        lock().notifyAll();
+                    }
+                }
+            });
+            if (getDeferred(false) != null) {
+                return null;
+            }
+        }
+        return top;
+    }
+
     private StringBuilder deferred;
     private boolean deferredDisabled;
     private Collection<Object> arguments = new LinkedList<Object>();


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists