Path: blob/master/test/jdk/java/awt/Component/TreeLockDeadlock/TreeLockDeadlock.java
41153 views
/*1* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.awt.Frame;24import java.awt.GraphicsConfiguration;25import java.awt.Window;2627import static java.util.concurrent.TimeUnit.MINUTES;28import static java.util.concurrent.TimeUnit.NANOSECONDS;2930/**31* @test32* @key headful33* @bug 813876434*/35public final class TreeLockDeadlock extends Frame {3637@Override38public synchronized GraphicsConfiguration getGraphicsConfiguration() {39return super.getGraphicsConfiguration();40}4142@Override43public synchronized void reshape(int x, int y, int width, int height) {44super.reshape(x, y, width, height);45}4647@Override48public synchronized float getOpacity() {49return super.getOpacity();50}5152public static void main(final String[] args) throws Exception {53final Window window = new TreeLockDeadlock();54window.setSize(300, 300);55test(window);56}5758private static void test(final Window window) throws Exception {59final long start = System.nanoTime();60final long end = start + NANOSECONDS.convert(1, MINUTES);6162final Runnable r1 = () -> {63while (System.nanoTime() < end) {64window.setBounds(window.getBounds());65}66};67final Runnable r2 = () -> {68while (System.nanoTime() < end) {69window.getGraphicsConfiguration();70window.getOpacity();71}72};7374final Thread t1 = new Thread(r1);75final Thread t2 = new Thread(r1);76final Thread t3 = new Thread(r2);77final Thread t4 = new Thread(r2);7879t1.start();80t2.start();81t3.start();82t4.start();83t1.join();84t2.join();85t3.join();86t4.join();87}88}899091