changeset 10797:db989e88ef7f

8078606: Deadlock in awt clipboard Reviewed-by: azvegint, bae
author anashaty
date Thu, 04 Jun 2015 15:29:07 +0300
parents 00229154077d
children b26427c5b3fe
files src/solaris/classes/sun/awt/X11/XClipboard.java src/solaris/classes/sun/awt/X11/XRootWindow.java
diffstat 2 files changed, 32 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/src/solaris/classes/sun/awt/X11/XClipboard.java	Wed Jun 03 17:48:27 2015 +0300
+++ b/src/solaris/classes/sun/awt/X11/XClipboard.java	Thu Jun 04 15:29:07 2015 +0300
@@ -156,19 +156,29 @@
         isSelectionNotifyProcessed = true;
 
         boolean mustSchedule = false;
-        synchronized (XClipboard.classLock) {
-            if (targetsAtom2Clipboard == null) {
-                targetsAtom2Clipboard = new HashMap<Long, XClipboard>(2);
+        XToolkit.awtLock();
+        try {
+            synchronized (XClipboard.classLock) {
+                try {
+                    Thread.sleep(70);
+                } catch (InterruptedException e) {
+                    e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+                }
+                if (targetsAtom2Clipboard == null) {
+                    targetsAtom2Clipboard = new HashMap<Long, XClipboard>(2);
+                }
+                mustSchedule = targetsAtom2Clipboard.isEmpty();
+                targetsAtom2Clipboard.put(getTargetsPropertyAtom().getAtom(), this);
+                if (mustSchedule) {
+                    XToolkit.addEventDispatcher(XWindow.getXAWTRootWindow().getWindow(),
+                                                new SelectionNotifyHandler());
+                }
             }
-            mustSchedule = targetsAtom2Clipboard.isEmpty();
-            targetsAtom2Clipboard.put(getTargetsPropertyAtom().getAtom(), this);
             if (mustSchedule) {
-                XToolkit.addEventDispatcher(XWindow.getXAWTRootWindow().getWindow(),
-                                            new SelectionNotifyHandler());
+                XToolkit.schedule(new CheckChangeTimerTask(), XClipboard.getPollInterval());
             }
-        }
-        if (mustSchedule) {
-            XToolkit.schedule(new CheckChangeTimerTask(), XClipboard.getPollInterval());
+        } finally {
+            XToolkit.awtUnlock();
         }
     }
 
--- a/src/solaris/classes/sun/awt/X11/XRootWindow.java	Wed Jun 03 17:48:27 2015 +0300
+++ b/src/solaris/classes/sun/awt/X11/XRootWindow.java	Thu Jun 04 15:29:07 2015 +0300
@@ -31,18 +31,22 @@
  * common logical ancestor
  */
 class XRootWindow extends XBaseWindow {
-    private static XRootWindow xawtRootWindow = null;
-    static XRootWindow getInstance() {
-        XToolkit.awtLock();
-        try {
-            if (xawtRootWindow == null) {
+    private static class LazyHolder {
+        private static final XRootWindow xawtRootWindow;
+
+        static {
+            XToolkit.awtLock();
+            try {
                 xawtRootWindow = new XRootWindow();
                 xawtRootWindow.init(xawtRootWindow.getDelayedParams().delete(DELAYED));
+            } finally {
+                XToolkit.awtUnlock();
             }
-            return xawtRootWindow;
-        } finally {
-            XToolkit.awtUnlock();
         }
+
+    }
+    static XRootWindow getInstance() {
+        return LazyHolder.xawtRootWindow;
     }
 
     private XRootWindow() {