Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 *
 *  The contents of this file are subject to the Terracotta Public License Version
 *  2.0 (the "License"); You may not use this file except in compliance with the
 *  License. You may obtain a copy of the License at
 *
 *  http://terracotta.org/legal/terracotta-public-license.
 *
 *  Software distributed under the License is distributed on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 *  the specific language governing rights and limitations under the License.
 *
 *  The Covered Software is Terracotta Core.
 *
 *  The Initial Developer of the Covered Software is
 *  Terracotta, Inc., a Software AG company
 *
 */

import java.lang.management.LockInfo;

import java.lang.management.ThreadInfo;

public class Main {
    private static String threadLockedSynchronizers(ThreadInfo threadInfo) {
        final String NO_SYNCH_INFO = "no locked synchronizers information available\n";
        if (null == threadInfo) {
            return NO_SYNCH_INFO;
        }
        try {
            final LockInfo[] lockInfos = threadInfo.getLockedSynchronizers();
            if (lockInfos.length > 0) {
                final StringBuffer lockedSynchBuff = new StringBuffer();
                lockedSynchBuff.append("\nLocked Synchronizers: \n");
                for (final LockInfo lockInfo : lockInfos) {
                    lockedSynchBuff.append(lockInfo.getClassName()).append(" <")
                            .append(lockInfo.getIdentityHashCode()).append("> \n");
                }
                return lockedSynchBuff.append("\n").toString();
            } else {
                return "";
            }
        } catch (final Exception e) {
            return NO_SYNCH_INFO;
        }
    }
}