2916N/A/*
2916N/A * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
2916N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2916N/A *
2916N/A * This code is free software; you can redistribute it and/or modify it
2916N/A * under the terms of the GNU General Public License version 2 only, as
2916N/A * published by the Free Software Foundation.
2916N/A *
2916N/A * This code is distributed in the hope that it will be useful, but WITHOUT
2916N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2916N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2916N/A * version 2 for more details (a copy is included in the LICENSE file that
2916N/A * accompanied this code).
2916N/A *
2916N/A * You should have received a copy of the GNU General Public License version
2916N/A * 2 along with this work; if not, write to the Free Software Foundation,
2916N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2916N/A *
2916N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2916N/A * or visit www.oracle.com if you need additional information or have any
2916N/A * questions.
2916N/A */
2916N/A
2916N/Aimport java.util.Properties;
2916N/Aimport java.util.concurrent.CyclicBarrier;
2916N/Aimport java.util.concurrent.BrokenBarrierException;
2916N/Aimport java.io.IOException;
2916N/Aimport java.net.URL;
2916N/A
2916N/A/* @test
2916N/A * @bug 6977738
2916N/A * @summary Test ClassLoader.getResource() that should not deadlock
2916N/A # if another thread is holding the system properties object
2916N/A *
2916N/A * @build GetResource
2916N/A * @run main GetResource
2916N/A */
2916N/A
2916N/Apublic class GetResource {
2916N/A CyclicBarrier go = new CyclicBarrier(2);
2916N/A CyclicBarrier done = new CyclicBarrier(2);
2916N/A Thread t1, t2;
2916N/A public GetResource() {
2916N/A t1 = new Thread() {
2916N/A public void run() {
2916N/A Properties prop = System.getProperties();
2916N/A synchronized (prop) {
2916N/A System.out.println("Thread 1 ready");
2916N/A try {
2916N/A go.await();
2916N/A prop.put("property", "value");
2916N/A prop.store(System.out, "");
2916N/A done.await(); // keep holding the lock until t2 finishes
2916N/A } catch (InterruptedException e) {
2916N/A throw new RuntimeException(e);
2916N/A } catch (BrokenBarrierException e) {
2916N/A throw new RuntimeException(e);
2916N/A } catch (IOException e) {
2916N/A throw new RuntimeException(e);
2916N/A }
2916N/A }
2916N/A System.out.println("Thread 1 exits");
2916N/A }
2916N/A };
2916N/A
2916N/A t2 = new Thread() {
2916N/A public void run() {
2916N/A System.out.println("Thread 2 ready");
2916N/A try {
2916N/A go.await(); // wait until t1 holds the lock of the system properties
2916N/A
2916N/A URL u1 = Thread.currentThread().getContextClassLoader().getResource("unknownresource");
2916N/A URL u2 = Thread.currentThread().getContextClassLoader().getResource("sun/util/resources/CalendarData.class");
2916N/A if (u2 == null) {
2916N/A throw new RuntimeException("Test failed: resource not found");
2916N/A }
2916N/A done.await();
2916N/A } catch (InterruptedException e) {
2916N/A throw new RuntimeException(e);
2916N/A } catch (BrokenBarrierException e) {
2916N/A throw new RuntimeException(e);
2916N/A }
2916N/A System.out.println("Thread 2 exits");
2916N/A }
2916N/A };
2916N/A }
2916N/A
2916N/A public void run() throws Exception {
2916N/A t1.start();
2916N/A t2.start();
2916N/A try {
2916N/A t1.join();
2916N/A } catch (InterruptedException e) {
2916N/A e.printStackTrace();
2916N/A throw e;
2916N/A }
2916N/A try {
2916N/A t2.join();
2916N/A } catch (InterruptedException e) {
2916N/A e.printStackTrace();
2916N/A throw e;
2916N/A }
2916N/A }
2916N/A
2916N/A public static void main(String[] args) throws Exception {
2916N/A new GetResource().run();
2916N/A }
2916N/A}