Esempio n. 1
0
 // 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();
 }
Esempio n. 3
0
  /** Uses reflection to run the Java 1.6 method 'findDeadlockedThreads' on a bean. */
  private static long[] findDeadlockedThreads(ThreadMXBean bean) {
    try {
      Method m = ThreadMXBean.class.getMethod("findDeadlockedThreads");
      Object o = m.invoke(bean);
      if (o instanceof long[] || o == null) return (long[]) o;
    } catch (Throwable t) {
    }

    // fallback to the monitor'd one if anything bad happens.
    return bean.findMonitorDeadlockedThreads();
  }
Esempio n. 4
0
  @Override
  public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws IOException {
    SimpleOrderedMap<Object> system = new SimpleOrderedMap<Object>();
    rsp.add("system", system);

    ThreadMXBean tmbean = ManagementFactory.getThreadMXBean();

    // Thread Count
    SimpleOrderedMap<Object> nl = new SimpleOrderedMap<Object>();
    nl.add("current", tmbean.getThreadCount());
    nl.add("peak", tmbean.getPeakThreadCount());
    nl.add("daemon", tmbean.getDaemonThreadCount());
    system.add("threadCount", nl);

    // Deadlocks
    ThreadInfo[] tinfos;
    long[] tids = tmbean.findMonitorDeadlockedThreads();
    if (tids != null) {
      tinfos = tmbean.getThreadInfo(tids, Integer.MAX_VALUE);
      NamedList<SimpleOrderedMap<Object>> lst = new NamedList<SimpleOrderedMap<Object>>();
      for (ThreadInfo ti : tinfos) {
        if (ti != null) {
          lst.add("thread", getThreadInfo(ti, tmbean));
        }
      }
      system.add("deadlocks", lst);
    }

    // Now show all the threads....
    tids = tmbean.getAllThreadIds();
    tinfos = tmbean.getThreadInfo(tids, Integer.MAX_VALUE);
    NamedList<SimpleOrderedMap<Object>> lst = new NamedList<SimpleOrderedMap<Object>>();
    for (ThreadInfo ti : tinfos) {
      if (ti != null) {
        lst.add("thread", getThreadInfo(ti, tmbean));
      }
    }
    system.add("threadDump", lst);
    rsp.setHttpCaching(false);
  }
  /* (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;
  }