/** * Check if any threads are deadlocked. If any, print the thread dump for those threads. * * @return a deadlock message and the formatted thread dump of the deadlocked threads */ private static String findDeadlock() { ThreadInfo[] tinfos = null; long[] ids = threadMXBean.findDeadlockedThreads(); if (ids != null) { tinfos = threadMXBean.getThreadInfo(threadMXBean.findDeadlockedThreads(), true, true); if (tinfos != null) { StringBuilder sb = new StringBuilder("Deadlock found between the following threads:"); sb.append(CRLF); sb.append(getThreadDump(tinfos)); return sb.toString(); } } return ""; }
public ThreadInfo[] getDeadLocks() { final long[] ids = _tmx.findDeadlockedThreads(); if (ids != null) { return _tmx.getThreadInfo(ids, true, true); } else { return null; } }
// Return thread IDs of deadlocked threads or null if any. // It finds deadlocks involving only monitors if it's a Tiger VM. // Otherwise, it finds deadlocks involving both monitors and // the concurrent locks. public long[] findDeadlockedThreads() throws IOException { ThreadMXBean tm = getThreadMXBean(); if (supportsLockUsage && tm.isSynchronizerUsageSupported()) { return tm.findDeadlockedThreads(); } else { return tm.findMonitorDeadlockedThreads(); } }
private long[] findDeadlockedThreads(ThreadMXBean mbean) { // JDK 1.5 only supports the findMonitorDeadlockedThreads() // method, so you need to comment out the following three lines if (mbean.isSynchronizerUsageSupported()) { return mbean.findDeadlockedThreads(); } return mbean.findMonitorDeadlockedThreads(); }
@Override public void run() { while (doRun) { long[] threadIds = tmxb.findDeadlockedThreads(); try { // ... Thread.sleep(10000); } catch (InterruptedException ex) { Logger.getLogger(DeadLockDetector.class.getName()).log(Level.SEVERE, null, ex); } } }
/* (non-Javadoc) * @see org.epics.pvaccess.server.plugins.BeaconServerStatusProvider#getServerStatusData() */ public PVField getServerStatusData() { status .getIntField("connections") .put(context.getTransportRegistry().numberOfActiveTransports()); status.getLongField("allocatedMemory").put(Runtime.getRuntime().totalMemory()); status.getLongField("freeMemory").put(Runtime.getRuntime().freeMemory()); ThreadMXBean threadMBean = ManagementFactory.getThreadMXBean(); status.getIntField("threads").put(threadMBean.getThreadCount()); final long[] deadlocks = threadMBean.isSynchronizerUsageSupported() ? threadMBean.findDeadlockedThreads() : threadMBean.findMonitorDeadlockedThreads(); status.getIntField("deadlocks").put((deadlocks != null) ? deadlocks.length : 0); OperatingSystemMXBean osMBean = ManagementFactory.getOperatingSystemMXBean(); status.getDoubleField("averageSystemLoad").put(osMBean.getSystemLoadAverage()); return status; }
@Override public void run() { boolean dead = false; while (!dead && !interrupted()) { try { Thread.sleep(10000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); dead = true; } ThreadMXBean tmx = ManagementFactory.getThreadMXBean(); long[] ids = tmx.findDeadlockedThreads(); if (ids != null) { Spout.getLogger().info("Checking for deadlocks"); ThreadInfo[] infos = tmx.getThreadInfo(ids, true, true); Spout.getLogger().severe("The following threads are deadlocked:"); for (ThreadInfo ti : infos) { Spout.getLogger().severe(ti.toString()); } } } }
@RequestMapping("/deadlockCheck") @ResponseBody public JSONObject doDeadlockCheck(HttpServletRequest request) { try { String app = request.getParameter("app"); ThreadMXBean tBean = JMConnManager.getThreadMBean(app); JSONObject json = new JSONObject(); long[] dTh = tBean.findDeadlockedThreads(); if (dTh != null) { ThreadInfo[] threadInfo = tBean.getThreadInfo(dTh, Integer.MAX_VALUE); StringBuffer sb = new StringBuffer(); for (ThreadInfo info : threadInfo) { sb.append("\n").append(info); } json.put("hasdeadlock", true); json.put("info", sb); return json; } json.put("hasdeadlock", false); return json; } catch (IOException e) { throw new RuntimeException(e); } }
@Override public long[] findDeadlockedThreads() { ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); return threadMXBean.findDeadlockedThreads(); }