4364N/A/*
4364N/A * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
4364N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4364N/A *
4364N/A * This code is free software; you can redistribute it and/or modify it
4364N/A * under the terms of the GNU General Public License version 2 only, as
4364N/A * published by the Free Software Foundation.
4364N/A *
4364N/A * This code is distributed in the hope that it will be useful, but WITHOUT
4364N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4364N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4364N/A * version 2 for more details (a copy is included in the LICENSE file that
4364N/A * accompanied this code).
4364N/A *
4364N/A * You should have received a copy of the GNU General Public License version
4364N/A * 2 along with this work; if not, write to the Free Software Foundation,
4364N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4364N/A *
4364N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4364N/A * or visit www.oracle.com if you need additional information or have any
4364N/A * questions.
4364N/A */
4364N/A
4364N/A/* @test
4364N/A * @bug 7068328
4364N/A * @summary Test if getObjectName handles properly when called by
4364N/A * multiple threads simultaneously. Run in othervm mode to
4364N/A * make sure the object name is not initialized to begin with.
4364N/A * @run main/othervm GetObjectName
4364N/A */
4364N/A
4364N/Aimport java.lang.management.BufferPoolMXBean;
4364N/Aimport java.lang.management.ManagementFactory;
4364N/Aimport java.lang.management.PlatformLoggingMXBean;
4364N/Aimport java.lang.management.PlatformManagedObject;
4364N/Aimport java.util.ArrayList;
4364N/Aimport java.util.List;
4364N/Aimport java.util.concurrent.ExecutorService;
4364N/Aimport java.util.concurrent.Executors;
4364N/Aimport java.util.concurrent.LinkedBlockingQueue;
4364N/Aimport java.util.concurrent.TimeUnit;
4364N/A
4364N/Apublic class GetObjectName {
4364N/A private static boolean failed = false;
4364N/A public static void main(String[] args) throws Exception {
4364N/A int tasks = 10000;
4364N/A ExecutorService executor = Executors.newFixedThreadPool(10);
4364N/A submitTasks(executor, tasks);
4364N/A executor.shutdown();
4364N/A executor.awaitTermination(10, TimeUnit.SECONDS);
4364N/A if (!failed) {
4364N/A System.out.println("Test passed.");
4364N/A }
4364N/A }
4364N/A
4364N/A static void submitTasks(ExecutorService executor, int count) {
4364N/A for (int i=0; i < count && !failed; i++) {
4364N/A executor.execute(new Runnable() {
4364N/A @Override
4364N/A public void run() {
4364N/A List<PlatformManagedObject> mbeans = new ArrayList<>();
4364N/A mbeans.add(ManagementFactory.getPlatformMXBean(PlatformLoggingMXBean.class));
4364N/A mbeans.addAll(ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class));
4364N/A for (PlatformManagedObject pmo : mbeans) {
4364N/A // Name should not be null
4364N/A if (pmo.getObjectName() == null) {
4364N/A failed = true;
4364N/A throw new RuntimeException("TEST FAILED: getObjectName() returns null");
4364N/A }
4364N/A }
4364N/A }
4364N/A });
4364N/A }
4364N/A }
4364N/A}