1 /* 2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 import java.awt.Frame; 25 import java.awt.GraphicsConfiguration; 26 import java.awt.Window; 27 28 import static java.util.concurrent.TimeUnit.MINUTES; 29 import static java.util.concurrent.TimeUnit.NANOSECONDS; 30 31 /** 32 * @test 33 * @bug 8138764 34 */ 35 public final class TreeLockDeadlock extends Frame { 36 37 @Override 38 public synchronized GraphicsConfiguration getGraphicsConfiguration() { 39 return super.getGraphicsConfiguration(); 40 } 41 42 @Override 43 public synchronized void reshape(int x, int y, int width, int height) { 44 super.reshape(x, y, width, height); 45 } 46 47 @Override 48 public synchronized float getOpacity() { 49 return super.getOpacity(); 50 } 51 52 public static void main(final String[] args) throws Exception { 53 final Window window = new TreeLockDeadlock(); 54 window.setSize(300, 300); 55 test(window); 56 } 57 58 private static void test(final Window window) throws Exception { 59 final long start = System.nanoTime(); 60 final long end = start + NANOSECONDS.convert(1, MINUTES); 61 62 final Runnable r1 = () -> { 63 while (System.nanoTime() < end) { 64 window.setBounds(window.getBounds()); 65 } 66 }; 67 final Runnable r2 = () -> { 68 while (System.nanoTime() < end) { 69 window.getGraphicsConfiguration(); 70 window.getOpacity(); 71 } 72 }; 73 74 final Thread t1 = new Thread(r1); 75 final Thread t2 = new Thread(r1); 76 final Thread t3 = new Thread(r2); 77 final Thread t4 = new Thread(r2); 78 79 t1.start(); 80 t2.start(); 81 t3.start(); 82 t4.start(); 83 t1.join(); 84 t2.join(); 85 t3.join(); 86 t4.join(); 87 } 88 }