List of usage examples for java.lang Thread getPriority
public final int getPriority()
From source file:org.sakaiproject.status.StatusServlet.java
protected void reportThreadDetails(HttpServletResponse response) throws Exception { PrintWriter pw = response.getWriter(); for (Thread thread : findAllThreads()) { if (thread != null) { String threadLocation = ""; try { StackTraceElement ste = thread.getStackTrace()[0]; StackTraceElement ste2 = thread.getStackTrace()[1]; threadLocation = ste.getClassName() + "." + ste.getMethodName() + "()," + ste.getFileName() + ":" + ste.getLineNumber() + "," + ste2.getClassName() + "." + ste2.getMethodName() + "()," + ste2.getFileName() + ":" + ste2.getLineNumber(); } catch (Exception e) { threadLocation = "?,?,?,?"; }/*from ww w. j a v a 2s . co m*/ pw.print(thread.getThreadGroup().getName() + "," + thread.getId() + "," + thread.getName() + "," + thread.getPriority() + "," + thread.getState().name() + "," + (thread.isAlive() ? "" : "notalive") + "," + (thread.isDaemon() ? "daemon" : "") + "," + (thread.isInterrupted() ? "interrupted" : "") + "," + threadLocation + "\n"); } } }
From source file:org.tranche.logs.LogUtil.java
/** * // w w w . j a va 2 s . com * @return */ public static final String getThreadDump() { Map<Thread, StackTraceElement[]> threadInfo = Thread.getAllStackTraces(); StringBuffer buf = new StringBuffer(); buf.append("Thread dump: " + threadInfo.size() + " threads"); buf.append("\n" + "\n"); for (Thread t : threadInfo.keySet()) { StackTraceElement[] ste = threadInfo.get(t); String daemonMsg = t.isDaemon() ? "daemon" : "non-daemon"; String aliveMsg = t.isAlive() ? "alive" : "non-alive"; buf.append(" * " + t.getName() + " (priority: " + t.getPriority() + ", " + daemonMsg + ", " + aliveMsg + ", state: " + t.getState() + ") "); buf.append("\n"); for (int i = 0; i < ste.length; i++) { buf.append(" " + ste[i].toString()); buf.append("\n"); } buf.append("\n"); } buf.append("\n" + "\n"); return buf.toString(); }
From source file:voltkvqa.AsyncBenchmark.java
/** * Fake an internal jstack to the log//from w ww. ja v a2 s. com */ static public void printJStack() { prt(new Date().toString() + " Full thread dump"); Map<String, List<String>> deduped = new HashMap<String, List<String>>(); // collect all the output, but dedup the identical stack traces for (Entry<Thread, StackTraceElement[]> e : Thread.getAllStackTraces().entrySet()) { Thread t = e.getKey(); String header = String.format("\"%s\" %sprio=%d tid=%d %s", t.getName(), t.isDaemon() ? "daemon " : "", t.getPriority(), t.getId(), t.getState().toString()); String stack = ""; for (StackTraceElement ste : e.getValue()) { stack += " at " + ste.toString() + "\n"; } if (deduped.containsKey(stack)) { deduped.get(stack).add(header); } else { ArrayList<String> headers = new ArrayList<String>(); headers.add(header); deduped.put(stack, headers); } } for (Entry<String, List<String>> e : deduped.entrySet()) { String logline = ""; for (String header : e.getValue()) { logline += header + "\n"; } logline += e.getKey(); prt(logline); } }