Path: blob/master/test/jdk/java/beans/Introspector/Test6963811.java
41149 views
/*1* Copyright (c) 2010, 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*/2223/*24* @test25* @bug 696381126* @summary Tests deadlock in Introspector27* @author Sergey Malenkov28*/2930import java.beans.Introspector;31import java.beans.SimpleBeanInfo;3233public class Test6963811 implements Runnable {34private final long time;35private final boolean sync;3637public Test6963811(long time, boolean sync) {38this.time = time;39this.sync = sync;40}4142public void run() {43try {44Thread.sleep(this.time); // increase the chance of the deadlock45Introspector.getBeanInfo(46this.sync ? Super.class : Sub.class,47this.sync ? null : Object.class);48}49catch (Exception exception) {50exception.printStackTrace();51}52}5354public static void main(String[] args) throws Exception {55Thread[] threads = new Thread[2];56for (int i = 0; i < threads.length; i++) {57threads[i] = new Thread(new Test6963811(0L, i > 0));58threads[i].start();59Thread.sleep(500L); // increase the chance of the deadlock60}61for (Thread thread : threads) {62thread.join();63}64}6566public static class Super {67}6869public static class Sub extends Super {70}7172public static class SubBeanInfo extends SimpleBeanInfo {73public SubBeanInfo() {74new Test6963811(1000L, true).run();75}76}77}787980