Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/lang/management/ManagementFactory/GetObjectName.java
38828 views
/*1* Copyright (c) 2011, 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/* @test24* @bug 706832825* @summary Test if getObjectName handles properly when called by26* multiple threads simultaneously. Run in othervm mode to27* make sure the object name is not initialized to begin with.28* @run main/othervm GetObjectName29*/3031import java.lang.management.BufferPoolMXBean;32import java.lang.management.ManagementFactory;33import java.lang.management.PlatformLoggingMXBean;34import java.lang.management.PlatformManagedObject;35import java.util.ArrayList;36import java.util.List;37import java.util.concurrent.ExecutorService;38import java.util.concurrent.Executors;39import java.util.concurrent.LinkedBlockingQueue;40import java.util.concurrent.TimeUnit;4142public class GetObjectName {43private static boolean failed = false;44public static void main(String[] args) throws Exception {45int tasks = 10000;46ExecutorService executor = Executors.newFixedThreadPool(10);47submitTasks(executor, tasks);48executor.shutdown();49executor.awaitTermination(10, TimeUnit.SECONDS);50if (!failed) {51System.out.println("Test passed.");52}53}5455static void submitTasks(ExecutorService executor, int count) {56for (int i=0; i < count && !failed; i++) {57executor.execute(new Runnable() {58@Override59public void run() {60List<PlatformManagedObject> mbeans = new ArrayList<>();61mbeans.add(ManagementFactory.getPlatformMXBean(PlatformLoggingMXBean.class));62mbeans.addAll(ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class));63for (PlatformManagedObject pmo : mbeans) {64// Name should not be null65if (pmo.getObjectName() == null) {66failed = true;67throw new RuntimeException("TEST FAILED: getObjectName() returns null");68}69}70}71});72}73}74}757677