Java tutorial
//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.ThreadInfo; public class Main { private static void threadHeader(StringBuilder sb, ThreadInfo threadInfo) { final String threadName = threadInfo.getThreadName(); sb.append("\""); sb.append(threadName); sb.append("\" "); sb.append("Id="); sb.append(threadInfo.getThreadId()); try { final Thread.State threadState = threadInfo.getThreadState(); final String lockName = threadInfo.getLockName(); final String lockOwnerName = threadInfo.getLockOwnerName(); final Long lockOwnerId = threadInfo.getLockOwnerId(); final Boolean isSuspended = threadInfo.isSuspended(); final Boolean isInNative = threadInfo.isInNative(); sb.append(" "); sb.append(threadState); if (lockName != null) { sb.append(" on "); sb.append(lockName); } if (lockOwnerName != null) { sb.append(" owned by \""); sb.append(lockOwnerName); sb.append("\" Id="); sb.append(lockOwnerId); } if (isSuspended) { sb.append(" (suspended)"); } if (isInNative) { sb.append(" (in native)"); } } catch (final Exception e) { sb.append(" ( Got exception : ").append(e.getMessage()).append(" :"); } sb.append('\n'); } }