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 * @key headful 34 * @bug 8138764 35 */ 36 public final class TreeLockDeadlock extends Frame { 37 38 @Override 39 public synchronized GraphicsConfiguration getGraphicsConfiguration() { 40 return super.getGraphicsConfiguration(); 41 } 42 43 @Override 44 public synchronized void reshape(int x, int y, int width, int height) { 45 super.reshape(x, y, width, height); 46 } 47 48 @Override 49 public synchronized float getOpacity() { 50 return super.getOpacity(); 51 } 52 53 public static void main(final String[] args) throws Exception { 54 final Window window = new TreeLockDeadlock(); 55 window.setSize(300, 300); 56 test(window); 57 } 58 59 private static void test(final Window window) throws Exception { 60 final long start = System.nanoTime(); 61 final long end = start + NANOSECONDS.convert(1, MINUTES); 62 63 final Runnable r1 = () -> { 64 while (System.nanoTime() < end) { 65 window.setBounds(window.getBounds()); 66 } 67 }; 68 final Runnable r2 = () -> { 69 while (System.nanoTime() < end) { 70 window.getGraphicsConfiguration(); 71 window.getOpacity(); 72 } 73 }; 74 75 final Thread t1 = new Thread(r1); 76 final Thread t2 = new Thread(r1); 77 final Thread t3 = new Thread(r2); 78 final Thread t4 = new Thread(r2); 79 80 t1.start(); 81 t2.start(); 82 t3.start(); 83 t4.start(); 84 t1.join(); 85 t2.join(); 86 t3.join(); 87 t4.join(); 88 } 89 }