Path: blob/master/test/jdk/java/beans/XMLEncoder/Test6963811.java
41152 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 Encoder27* @author Sergey Malenkov28*/2930import java.beans.Encoder;31import java.beans.DefaultPersistenceDelegate;3233public class Test6963811 implements Runnable {34private static final Encoder ENCODER = new Encoder();35private final long time;36private final boolean sync;3738public Test6963811(long time, boolean sync) {39this.time = time;40this.sync = sync;41}4243public void run() {44try {45Thread.sleep(this.time); // increase the chance of the deadlock46if (this.sync) {47synchronized (Test6963811.class) {48ENCODER.getPersistenceDelegate(Super.class);49}50}51else {52ENCODER.getPersistenceDelegate(Sub.class);53}54}55catch (Exception exception) {56exception.printStackTrace();57}58}5960public static void main(String[] args) throws Exception {61Thread[] threads = new Thread[2];62for (int i = 0; i < threads.length; i++) {63threads[i] = new Thread(new Test6963811(0L, i > 0));64threads[i].start();65Thread.sleep(500L); // increase the chance of the deadlock66}67for (Thread thread : threads) {68thread.join();69}70}7172public static class Super {73}7475public static class Sub extends Super {76}7778public static class SubPersistenceDelegate extends DefaultPersistenceDelegate {79public SubPersistenceDelegate() {80new Test6963811(1000L, true).run();81}82}83}848586