Path: blob/master/test/jdk/java/lang/management/ThreadMXBean/SharedSynchronizer.java
41152 views
/*1* Copyright (c) 2005, 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*/2223/*24* @test25* @bug 633757126* @summary Test if findDeadlockedThreads works for an ownable synchronizer27* in shared mode which has no owner when a thread is parked.28* @author Mandy Chung29*30* @run main/othervm SharedSynchronizer31*/323334import java.util.concurrent.*;35import java.lang.management.ManagementFactory;36import java.lang.management.ThreadMXBean;3738public class SharedSynchronizer {39public static void main(String[] args) throws Exception {40MyThread t = new MyThread();41t.setDaemon(true);42t.start();4344ThreadMXBean tmbean = ManagementFactory.getThreadMXBean();45if (!tmbean.isSynchronizerUsageSupported()) {46System.out.println("Monitoring of synchronizer usage not supported")47;48return;49}5051long[] result = tmbean.findDeadlockedThreads();52if (result != null) {53throw new RuntimeException("TEST FAILED: result should be null");54}55}5657static class MyThread extends Thread {58public void run() {59FutureTask f = new FutureTask(60new Callable() {61public Object call() {62throw new RuntimeException("should never reach here");63}64}65);6667// A FutureTask uses the AbstractOwnableSynchronizer in a shared68// mode (not exclusive mode). When the thread calls f.get(),69// it will put to park on the ownable synchronizer that70// is not owned by any thread.71try {72f.get();73} catch (Exception e) {74RuntimeException re = new RuntimeException(e.getMessage());75re.initCause(e);76throw re;77}78}79}80}818283