org.apache.commons.lang3.ThreadUtils Java Examples
The following examples show how to use
org.apache.commons.lang3.ThreadUtils.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MapViewTileRenderer.java From constellation with Apache License 2.0 | 6 votes |
/** * Note that this method is trying to remove references to the * NewtWindowListener as it's preventing the MapViewTileRenderer from being * garbage collected. This is still a work in progress. */ @Override public void dispose() { if (glComponent != null) { glComponent = null; } finished = true; if (surface != null && surface.stopThread() && g != null) { g.dispose(); } surface = null; // initSurface() creates HighResTimerThread threads that don't die so kill them manually final Collection<Thread> threadsToKill = ThreadUtils.findThreadsByName("HighResTimerThread"); for (final Thread thread : threadsToKill) { thread.interrupt(); } }
Example #2
Source File: ThreadDump.java From o2oa with GNU Affero General Public License v3.0 | 4 votes |
public void execute(Integer count) throws Exception { new Thread() { public void run() { try { Map<Long, Integer> state_new = new HashMap<>(); Map<Long, Integer> state_runable = new HashMap<>(); Map<Long, Integer> state_blocked = new HashMap<>(); Map<Long, Integer> state_waiting = new HashMap<>(); Map<Long, Integer> state_timed_waiting = new HashMap<>(); Map<Long, Integer> state_terminated = new HashMap<>(); File startFile = null; for (int i = 1; i <= count; i++) { Date date = new Date(); StringBuffer buffer = new StringBuffer(); for (Thread thread : ThreadUtils.getAllThreads()) { state(thread, state_new, state_runable, state_blocked, state_waiting, state_timed_waiting, state_terminated); dump(buffer, thread); } File file = new File(Config.dir_logs(true), fileName(i, count, date)); if (i == 1) { startFile = file; } if (i != count) { FileUtils.write(file, buffer, DefaultCharset.charset_utf_8); logger.print(String.format("thread dump to file(%d/%d): %s.", i, count, file.getAbsolutePath())); Thread.sleep(5000); } else { buffer.append(System.lineSeparator()).append("Thread state statistics:"); buffer.append(" NEW(" + state_new.size() + "),"); buffer.append(" RUNABLE(" + state_runable.size() + "),"); buffer.append(" blocked(" + state_blocked.size() + "),"); buffer.append(" waiting(" + state_waiting.size() + "),"); buffer.append(" timed_waiting(" + state_timed_waiting.size() + "),"); buffer.append(" terminated(" + state_terminated.size() + ")."); buffer.append(System.lineSeparator()); writeState(buffer, state_new, State.NEW, count); writeState(buffer, state_runable, State.RUNNABLE, count); writeState(buffer, state_blocked, State.BLOCKED, count); writeState(buffer, state_waiting, State.WAITING, count); writeState(buffer, state_timed_waiting, State.TIMED_WAITING, count); writeState(buffer, state_terminated, State.TERMINATED, count); FileUtils.write(file, buffer, DefaultCharset.charset_utf_8); logger.print(String.format("thread dump to files: %s - %s.", startFile.getAbsolutePath(), file.getAbsolutePath())); } } } catch (Exception e) { e.printStackTrace(); } } }.start(); }