1 /* 2 * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @bug 6337571 27 * @summary Test if findDeadlockedThreads works for an ownable synchronizer 28 * in shared mode which has no owner when a thread is parked. 29 * @author Mandy Chung 30 * 31 * @modules java.management 32 * @run main/othervm SharedSynchronizer 33 */ 34 35 36 import java.util.concurrent.*; 37 import java.lang.management.ManagementFactory; 38 import java.lang.management.ThreadMXBean; 39 40 public class SharedSynchronizer { 41 public static void main(String[] args) throws Exception { 42 MyThread t = new MyThread(); 43 t.setDaemon(true); 44 t.start(); 45 46 ThreadMXBean tmbean = ManagementFactory.getThreadMXBean(); 47 if (!tmbean.isSynchronizerUsageSupported()) { 48 System.out.println("Monitoring of synchronizer usage not supported") 49 ; 50 return; 51 } 52 53 long[] result = tmbean.findDeadlockedThreads(); 54 if (result != null) { 55 throw new RuntimeException("TEST FAILED: result should be null"); 56 } 57 } 58 59 static class MyThread extends Thread { 60 public void run() { 61 FutureTask f = new FutureTask( 62 new Callable() { 63 public Object call() { 64 throw new RuntimeException("should never reach here"); 65 } 66 } 67 ); 68 69 // A FutureTask uses the AbstractOwnableSynchronizer in a shared 70 // mode (not exclusive mode). When the thread calls f.get(), 71 // it will put to park on the ownable synchronizer that 72 // is not owned by any thread. 73 try { 74 f.get(); 75 } catch (Exception e) { 76 RuntimeException re = new RuntimeException(e.getMessage()); 77 re.initCause(e); 78 throw re; 79 } 80 } 81 } 82 }