本文整理汇总了Java中java.lang.management.ThreadMXBean.dumpAllThreads方法的典型用法代码示例。如果您正苦于以下问题:Java ThreadMXBean.dumpAllThreads方法的具体用法?Java ThreadMXBean.dumpAllThreads怎么用?Java ThreadMXBean.dumpAllThreads使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.management.ThreadMXBean
的用法示例。
在下文中一共展示了ThreadMXBean.dumpAllThreads方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: render
import java.lang.management.ThreadMXBean; //导入方法依赖的package包/类
@Override
protected void render(Block html) {
set(TITLE, join("Angel ExecutorsBlock"));
TBODY<TABLE<Hamlet>> tbody =
html.h1("ExecutorsBlock").table("#jobs").thead().tr().th(_TH, "id").th(_TH, "name")
.th(_TH, "state").th(_TH, "stacktrace")._()._().tbody();
ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
ThreadInfo[] threadInfo = threadMXBean.dumpAllThreads(true, true);
StringBuilder stackTraceString;
for (ThreadInfo t : threadInfo) {
stackTraceString = new StringBuilder();
StackTraceElement[] stackTrace = t.getStackTrace();
for (StackTraceElement s : stackTrace) {
stackTraceString.append(s.toString()).append("\n");
}
tbody.tr().td(String.valueOf(t.getThreadId())).td(String.valueOf(t.getThreadName()))
.td(String.valueOf(t.getThreadState())).td(String.valueOf(stackTraceString.toString()))._();
}
tbody._()._();
}
示例2: getThreadStack
import java.lang.management.ThreadMXBean; //导入方法依赖的package包/类
/**
* Gets thread stack.
*
* @return the thread stack
*/
private String getThreadStack()
{
ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
ThreadInfo[] threadInfo = threadMXBean.dumpAllThreads(true, true);
StringBuilder stackTraceString= new StringBuilder("ParameterServer\n");
StringBuilder infoBlock= new StringBuilder("\n");
for(ThreadInfo t : threadInfo)
{
infoBlock = new StringBuilder("\n\n");
infoBlock.append("threadid: ").append(t.getThreadId()).append(" threadname: ").append(t.getThreadName()).append(" threadstate: ").append(t.getThreadState()).append("\n");
for(StackTraceElement stackTraceElement : t.getStackTrace())
{
infoBlock.append(" ").append(stackTraceElement.toString()).append("\n");
}
stackTraceString.append(infoBlock).append("\n\n");
}
return stackTraceString.toString();
}
示例3: isMonitorLockHeldByThread
import java.lang.management.ThreadMXBean; //导入方法依赖的package包/类
public static boolean isMonitorLockHeldByThread(Object o, Thread t) {
int oihc = System.identityHashCode(o);
ThreadMXBean tmxbean = ManagementFactory.getThreadMXBean();
ThreadInfo[] tinfos = tmxbean.dumpAllThreads(true, false);
for (ThreadInfo ti : tinfos) {
if (!(t != null && t.getId() != ti.getThreadId())) {
for (MonitorInfo mi : ti.getLockedMonitors()) {
if (mi.getIdentityHashCode() == oihc) {
return true;
}
}
}
}
return false;
}
示例4: dumpTestThreads
import java.lang.management.ThreadMXBean; //导入方法依赖的package包/类
/**
* A debugging tool to print stack traces of most threads, as jstack does.
* Uninteresting threads are filtered out.
*/
static void dumpTestThreads() {
ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
System.err.println("------ stacktrace dump start ------");
for (ThreadInfo info : threadMXBean.dumpAllThreads(true, true)) {
String name = info.getThreadName();
if ("Signal Dispatcher".equals(name))
continue;
if ("Reference Handler".equals(name)
&& info.getLockName().startsWith("java.lang.ref.Reference$Lock"))
continue;
if ("Finalizer".equals(name)
&& info.getLockName().startsWith("java.lang.ref.ReferenceQueue$Lock"))
continue;
System.err.print(info);
}
System.err.println("------ stacktrace dump end ------");
}
示例5: dumpTestThreads
import java.lang.management.ThreadMXBean; //导入方法依赖的package包/类
/**
* A debugging tool to print stack traces of most threads, as jstack does.
* Uninteresting threads are filtered out.
*/
static void dumpTestThreads() {
ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
System.err.println("------ stacktrace dump start ------");
for (ThreadInfo info : threadMXBean.dumpAllThreads(true, true)) {
String name = info.getThreadName();
if ("Signal Dispatcher".equals(name))
continue;
if ("Reference Handler".equals(name)
&& info.getLockName().startsWith("java.lang.ref.Reference$Lock"))
continue;
if ("Finalizer".equals(name)
&& info.getLockName().startsWith("java.lang.ref.ReferenceQueue$Lock"))
continue;
if ("process reaper".equals(name))
continue;
if (name != null && name.startsWith("ForkJoinPool.commonPool-worker"))
continue;
System.err.print(info);
}
System.err.println("------ stacktrace dump end ------");
}
示例6: getThreadStack
import java.lang.management.ThreadMXBean; //导入方法依赖的package包/类
private String getThreadStack() {
ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
ThreadInfo[] threadInfo = threadMXBean.dumpAllThreads(true, true);
StringBuilder stackTraceString = new StringBuilder("Worker\n");
StringBuilder infoBlock = new StringBuilder("\n");
for (ThreadInfo t : threadInfo) {
infoBlock = new StringBuilder("\n\n");
infoBlock.append("threadid: ").append(t.getThreadId()).append(" threadname: ").append(t.getThreadName()).append(" threadstate: ").append(t.getThreadState()).append("\n");
for (StackTraceElement stackTraceElement : t.getStackTrace()) {
infoBlock.append(" ").append(stackTraceElement.toString()).append("\n");
}
stackTraceString.append(infoBlock).append("\n\n");
}
return stackTraceString.toString();
}
示例7: dumpTestThreads
import java.lang.management.ThreadMXBean; //导入方法依赖的package包/类
/**
* A debugging tool to print stack traces of most threads, as jstack does.
* Uninteresting threads are filtered out.
*/
static void dumpTestThreads() {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
try {
System.setSecurityManager(null);
} catch (SecurityException giveUp) {
return;
}
}
ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
System.err.println("------ stacktrace dump start ------");
for (ThreadInfo info : threadMXBean.dumpAllThreads(true, true)) {
final String name = info.getThreadName();
String lockName;
if ("Signal Dispatcher".equals(name))
continue;
if ("Reference Handler".equals(name)
&& (lockName = info.getLockName()) != null
&& lockName.startsWith("java.lang.ref.Reference$Lock"))
continue;
if ("Finalizer".equals(name)
&& (lockName = info.getLockName()) != null
&& lockName.startsWith("java.lang.ref.ReferenceQueue$Lock"))
continue;
if ("checkForWedgedTest".equals(name))
continue;
System.err.print(info);
}
System.err.println("------ stacktrace dump end ------");
if (sm != null) System.setSecurityManager(sm);
}
示例8: run
import java.lang.management.ThreadMXBean; //导入方法依赖的package包/类
public void run()
{
while (this.server.isServerRunning())
{
long i = this.server.getCurrentTime();
long j = MinecraftServer.getCurrentTimeMillis();
long k = j - i;
if (k > this.maxTickTime)
{
LOGGER.fatal("A single server tick took " + String.format("%.2f", new Object[] {Float.valueOf((float)k / 1000.0F)}) + " seconds (should be max " + String.format("%.2f", new Object[] {Float.valueOf(0.05F)}) + ")");
LOGGER.fatal("Considering it to be crashed, server will forcibly shutdown.");
ThreadMXBean threadmxbean = ManagementFactory.getThreadMXBean();
ThreadInfo[] athreadinfo = threadmxbean.dumpAllThreads(true, true);
StringBuilder stringbuilder = new StringBuilder();
Error error = new Error();
for (ThreadInfo threadinfo : athreadinfo)
{
if (threadinfo.getThreadId() == this.server.getServerThread().getId())
{
error.setStackTrace(threadinfo.getStackTrace());
}
stringbuilder.append((Object)threadinfo);
stringbuilder.append("\n");
}
CrashReport crashreport = new CrashReport("Watching Server", error);
this.server.addServerInfoToCrashReport(crashreport);
CrashReportCategory crashreportcategory = crashreport.makeCategory("Thread Dump");
crashreportcategory.addCrashSection("Threads", stringbuilder);
File file1 = new File(new File(this.server.getDataDirectory(), "crash-reports"), "crash-" + (new SimpleDateFormat("yyyy-MM-dd_HH.mm.ss")).format(new Date()) + "-server.txt");
if (crashreport.saveToFile(file1))
{
LOGGER.error("This crash report has been saved to: " + file1.getAbsolutePath());
}
else
{
LOGGER.error("We were unable to save this crash report to disk.");
}
this.scheduleHalt();
}
try
{
Thread.sleep(i + this.maxTickTime - j);
}
catch (InterruptedException var15)
{
;
}
}
}
示例9: dumpAllThreads
import java.lang.management.ThreadMXBean; //导入方法依赖的package包/类
static void dumpAllThreads(Consumer<String> println) {
final ThreadMXBean threadMxBean = ManagementFactory.getThreadMXBean();
for (ThreadInfo ti : threadMxBean.dumpAllThreads(true, true)) {
println.accept(ti.toString());
}
}
示例10: getCurrentInfo
import java.lang.management.ThreadMXBean; //导入方法依赖的package包/类
public Map<Thread.State, Long> getCurrentInfo(MBeanServerConnection connection) {
ThreadMXBean threadBean = JMX.newMXBeanProxy(connection, threadsName, ThreadMXBean.class);
ThreadInfo[] threads = threadBean.dumpAllThreads(false,false);
// take copy of map with all possible states initialised to zero
EnumMap<Thread.State, Long> threadStates = initialThreadStates.clone();
for(ThreadInfo thread : threads) {
Thread.State state = thread.getThreadState();
threadStates.put(state, threadStates.get(state)+1);
}
return threadStates;
}
示例11: run
import java.lang.management.ThreadMXBean; //导入方法依赖的package包/类
public void run()
{
while (this.server.isServerRunning())
{
long i = this.server.getCurrentTime();
long j = MinecraftServer.getCurrentTimeMillis();
long k = j - i;
if (k > this.maxTickTime && !this.firstRun)
{
LOGGER.fatal("A single server tick took {} seconds (should be max {})", new Object[] {String.format("%.2f", new Object[]{Float.valueOf((float)k / 1000.0F)}), String.format("%.2f", new Object[]{Float.valueOf(0.05F)})});
LOGGER.fatal("Considering it to be crashed, server will forcibly shutdown.");
ThreadMXBean threadmxbean = ManagementFactory.getThreadMXBean();
ThreadInfo[] athreadinfo = threadmxbean.dumpAllThreads(true, true);
StringBuilder stringbuilder = new StringBuilder();
Error error = new Error();
for (ThreadInfo threadinfo : athreadinfo)
{
if (threadinfo.getThreadId() == this.server.getServerThread().getId())
{
error.setStackTrace(threadinfo.getStackTrace());
}
stringbuilder.append((Object)threadinfo);
stringbuilder.append("\n");
}
CrashReport crashreport = new CrashReport("Watching Server", error);
this.server.addServerInfoToCrashReport(crashreport);
CrashReportCategory crashreportcategory = crashreport.makeCategory("Thread Dump");
crashreportcategory.addCrashSection("Threads", stringbuilder);
File file1 = new File(new File(this.server.getDataDirectory(), "crash-reports"), "crash-" + (new SimpleDateFormat("yyyy-MM-dd_HH.mm.ss")).format(new Date()) + "-server.txt");
if (crashreport.saveToFile(file1))
{
LOGGER.error("This crash report has been saved to: {}", new Object[] {file1.getAbsolutePath()});
}
else
{
LOGGER.error("We were unable to save this crash report to disk.");
}
this.scheduleHalt();
}
this.firstRun = false;
try
{
Thread.sleep(i + this.maxTickTime - j);
}
catch (InterruptedException var15)
{
;
}
}
}