List of usage examples for java.lang Thread activeCount
public static int activeCount()
From source file:Main.java
public static int getThreadCount() { return Thread.activeCount(); }
From source file:Main.java
public static void waitUntilLe(int activeThreadCount) { while (Thread.activeCount() > activeThreadCount) { try {//w w w .j av a 2s. c o m Thread.sleep(1 * 1000); } catch (InterruptedException e) { return; } } }
From source file:Main.java
public static String getAllThreadNames() { Thread[] array = new Thread[Thread.activeCount()]; Thread.enumerate(array);//ww w. jav a 2 s . c o m String s = ""; for (Thread t : array) { if (t != null) { s += t.getName() + ", "; } } return s; }
From source file:com.liferay.portal.events.LogThreadCountAction.java
public void run(HttpServletRequest req, HttpServletResponse res) throws ActionException { _log.debug("Active Threads:\t" + Thread.activeCount()); }
From source file:com.nubits.nubot.utils.Utils.java
public static void logActiveThreads() { int active = Thread.activeCount(); LOG.trace("currently active threads: " + active); Thread allThreads[] = new Thread[active]; Thread.enumerate(allThreads); for (int i = 0; i < active; i++) { Thread t = allThreads[i]; LOG.trace(i + ": " + t + " id: " + t.getId() + " name: " + t.getName() + " " + t.getContextClassLoader() + " group: " + t.getThreadGroup() + " alive" + t.isAlive()); LOG.trace("super: " + t.getClass().getSuperclass()); }//from w ww. ja v a 2 s. c o m if (active > maxThreadsError) { LOG.error("too many threads started"); } }
From source file:org.commonjava.indy.diag.data.DiagnosticsManager.java
public String getThreadDumpString() { Thread[] threads = new Thread[Thread.activeCount()]; Thread.enumerate(threads);/*w w w . jav a 2 s . c o m*/ Map<Long, Thread> threadMap = new HashMap<>(); Stream.of(threads).forEach(t -> threadMap.put(t.getId(), t)); ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); ThreadInfo[] threadInfos = threadMXBean.getThreadInfo(threadMXBean.getAllThreadIds(), 100); StringBuilder sb = new StringBuilder(); Stream.of(threadInfos).forEachOrdered((ti) -> { if (sb.length() > 0) { sb.append("\n\n"); } String threadGroup = "Unknown"; Thread t = threadMap.get(ti.getThreadId()); if (t != null) { ThreadGroup tg = t.getThreadGroup(); if (tg != null) { threadGroup = tg.getName(); } } sb.append(ti.getThreadName()).append("\n Group: ").append(threadGroup).append("\n State: ") .append(ti.getThreadState()).append("\n Lock Info: ").append(ti.getLockInfo()) .append("\n Monitors:"); MonitorInfo[] monitors = ti.getLockedMonitors(); if (monitors == null || monitors.length < 1) { sb.append(" -NONE-"); } else { sb.append("\n - ").append(join(monitors, "\n - ")); } sb.append("\n Trace:\n ").append(join(ti.getStackTrace(), "\n ")); }); return sb.toString(); }
From source file:com.myJava.util.Util.java
public static void logAllThreadInformations() { int nb = Thread.activeCount(); Thread[] th = new Thread[nb + 100]; Thread.enumerate(th);/*from w w w . j av a 2s .c o m*/ boolean stop = false; Logger.defaultLogger().info("Thread information : " + nb + " threads."); for (int i = 0; i < th.length && !stop; i++) { if (th[i] == null) { stop = true; } else { String header = "Thread " + i + " (" + th[i].getName() + " / " + th[i].getId() + ")"; logThreadInformations(header, th[i]); } } }
From source file:ai.susi.server.api.susi.StatusService.java
@Override public JSONObject serviceImpl(Query post, HttpServletResponse response, Authorization rights, JsonObjectWithDefault permissions) throws APIException { post.setResponse(response, "application/javascript"); // generate json Runtime runtime = Runtime.getRuntime(); JSONObject json = new JSONObject(true); JSONObject system = new JSONObject(true); system.put("assigned_memory", runtime.maxMemory()); system.put("used_memory", runtime.totalMemory() - runtime.freeMemory()); system.put("available_memory", runtime.maxMemory() - runtime.totalMemory() + runtime.freeMemory()); system.put("cores", runtime.availableProcessors()); system.put("threads", Thread.activeCount()); system.put("runtime", System.currentTimeMillis() - Caretaker.startupTime); system.put("load_system_average", OS.getSystemLoadAverage()); system.put("load_system_cpu", OS.getSystemCpuLoad()); system.put("load_process_cpu", OS.getProcessCpuLoad()); system.put("server_threads", SusiServer.getServerThreads()); system.put("server_uri", SusiServer.getServerURI()); JSONObject index = new JSONObject(true); JSONObject messages = new JSONObject(true); JSONObject queue = new JSONObject(true); messages.put("queue", queue); JSONObject users = new JSONObject(true); JSONObject queries = new JSONObject(true); JSONObject accounts = new JSONObject(true); JSONObject user = new JSONObject(true); index.put("messages", messages); index.put("users", users); index.put("queries", queries); index.put("accounts", accounts); index.put("user", user); JSONObject client_info = new JSONObject(true); client_info.put("RemoteHost", post.getClientHost()); client_info.put("IsLocalhost", post.isLocalhostAccess() ? "true" : "false"); JSONObject request_header = new JSONObject(true); Enumeration<String> he = post.getRequest().getHeaderNames(); while (he.hasMoreElements()) { String h = he.nextElement(); request_header.put(h, post.getRequest().getHeader(h)); }// ww w . j a v a2 s. c om client_info.put("request_header", request_header); json.put("system", system); json.put("index", index); json.put("client_info", client_info); return json; }
From source file:org.loklak.api.susi.StatusService.java
@Override public JSONObject serviceImpl(Query post, HttpServletResponse response, Authorization rights, JSONObjectWithDefault permissions) throws APIException { post.setResponse(response, "application/javascript"); // generate json Runtime runtime = Runtime.getRuntime(); JSONObject json = new JSONObject(true); JSONObject system = new JSONObject(true); system.put("assigned_memory", runtime.maxMemory()); system.put("used_memory", runtime.totalMemory() - runtime.freeMemory()); system.put("available_memory", runtime.maxMemory() - runtime.totalMemory() + runtime.freeMemory()); system.put("cores", runtime.availableProcessors()); system.put("threads", Thread.activeCount()); system.put("runtime", System.currentTimeMillis() - Caretaker.startupTime); system.put("load_system_average", OS.getSystemLoadAverage()); system.put("load_system_cpu", OS.getSystemCpuLoad()); system.put("load_process_cpu", OS.getProcessCpuLoad()); system.put("server_threads", SusiServer.getServerThreads()); system.put("server_uri", SusiServer.getServerURI()); JSONObject index = new JSONObject(true); JSONObject messages = new JSONObject(true); JSONObject queue = new JSONObject(true); messages.put("queue", queue); JSONObject users = new JSONObject(true); JSONObject queries = new JSONObject(true); JSONObject accounts = new JSONObject(true); JSONObject user = new JSONObject(true); index.put("messages", messages); index.put("users", users); index.put("queries", queries); index.put("accounts", accounts); index.put("user", user); JSONObject client_info = new JSONObject(true); client_info.put("RemoteHost", post.getClientHost()); client_info.put("IsLocalhost", post.isLocalhostAccess() ? "true" : "false"); JSONObject request_header = new JSONObject(true); Enumeration<String> he = post.getRequest().getHeaderNames(); while (he.hasMoreElements()) { String h = he.nextElement(); request_header.put(h, post.getRequest().getHeader(h)); }/*from w w w. j ava2 s . c o m*/ client_info.put("request_header", request_header); json.put("system", system); json.put("index", index); json.put("client_info", client_info); return json; }
From source file:seleniumAutomation.flowControls.java
public static void launchFlow(final String testCase) { try {/*from w w w.ja va2 s . c om*/ if (testCase.length() > 4) { while (Thread.activeCount() > 5) { Thread.sleep(1000); } Thread thread = new Thread() { public void run() { getSelenium().parseTestCase(testCase); return; } }; thread.start(); Thread.sleep(10); } } catch (InterruptedException ex) { Logger.getLogger(flowControls.class.getName()).log(Level.SEVERE, null, ex); } }