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

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

commit 534340c73115d93815fcd0017373e150ac470279
Author: Eirik Bakke <[email protected]>
AuthorDate: Sun Jan 7 00:28:48 2024 +0100

    Adjust the clipboard retry logic to use exponential backoff. It was 
creating a lot of logging messages, and clipboard access is a heavy operation 
that can sometimes interfere with other applications.
---
 platform/o.n.bootstrap/src/org/netbeans/NbClipboard.java | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/platform/o.n.bootstrap/src/org/netbeans/NbClipboard.java 
b/platform/o.n.bootstrap/src/org/netbeans/NbClipboard.java
index 1f9025e133f..49d8c728fdb 100644
--- a/platform/o.n.bootstrap/src/org/netbeans/NbClipboard.java
+++ b/platform/o.n.bootstrap/src/org/netbeans/NbClipboard.java
@@ -424,20 +424,25 @@ implements LookupListener, FlavorListener, 
AWTEventListener
                 // that is used because accessing the clipboard can block
                 // indefinitely. Running the access loop here is deemed similar
                 // in nature.
-                final int MAX_TRIES = 50;
+
+                /* The loop will actually stop before getting to 10 
iterations, per the delay
+                formula and conditional throw. But keep the MAX_TRIES just as 
a fail-safe. */
+                final int MAX_TRIES = 10;
                 final long start = System.currentTimeMillis();
+                int delay = 20;
                 for (int i = 0; i < MAX_TRIES; i++) {
                     try {
                         transferable = systemClipboard.getContents(this);
                         break;
                     } catch (IllegalStateException ex) {
                         // Throw exception if retries failed
-                        if (i == (MAX_TRIES - 1) || 
(System.currentTimeMillis() - start) > 980L) {
+                        if (i == (MAX_TRIES - 1) || 
(System.currentTimeMillis() + delay - start) > 1000L) {
                             throw ex;
                         } else {
-                            log.log(Level.INFO, "systemClipboard#getContents 
threw IllegalStateException (try: {0})", i + 1); // NOI18N
+                            log.log(Level.INFO, "systemClipboard#getContents 
ISE, attempt {0}", i + 1); // NOI18N
                         }
-                        Thread.sleep(20); // Give system time to settle
+                        Thread.sleep(delay); // Give system time to settle
+                        delay *= 2;
                     }
                 }
                 superSetContents(transferable, null);


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

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

Reply via email to