Skip to content

Commit

Permalink
0003797: Filter threads shown on Manage -> JVM Threads and snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
erilong committed Nov 15, 2018
1 parent edb120c commit c5ffcfc
Showing 1 changed file with 26 additions and 26 deletions.
Expand Up @@ -83,6 +83,7 @@
import org.jumpmind.symmetric.service.INodeService;
import org.jumpmind.symmetric.service.IParameterService;
import org.jumpmind.symmetric.service.ITriggerRouterService;
import org.jumpmind.symmetric.service.impl.UpdateService;
import org.jumpmind.util.AppUtils;
import org.jumpmind.util.ZipBuilder;
import org.slf4j.Logger;
Expand Down Expand Up @@ -265,25 +266,8 @@ public static File createSnapshot(ISymmetricEngine engine) {
}
}

fwriter = null;
try {
fwriter = new FileWriter(new File(tmpDir, "threads.txt"));
ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
long[] threadIds = threadBean.getAllThreadIds();
for (long l : threadIds) {
ThreadInfo info = threadBean.getThreadInfo(l, 100);
if (info != null) {
String threadName = info.getThreadName();
fwriter.append(StringUtils.rightPad(threadName, THREAD_INDENT_SPACE));
fwriter.append(AppUtils.formatStackTrace(info.getStackTrace(), THREAD_INDENT_SPACE, false));
fwriter.append("\n");
}
}
} catch (Exception e) {
log.warn("Failed to export thread information", e);
} finally {
IOUtils.closeQuietly(fwriter);
}
createThreadsFile(tmpDir.getPath(), false);
createThreadsFile(tmpDir.getPath(), true);

fos = null;
try {
Expand Down Expand Up @@ -673,10 +657,10 @@ public static Map<File, Layout> findSymmetricLogFile() {
}
return null;
}
public static File createThreadsFile() {

public static File createThreadsFile(String parent, boolean isFiltered) {
FileWriter fwriter = null;
File file = new File("threads.txt");
File file = new File(parent, isFiltered ? "threads-filtered.txt" : "threads.txt");
try {
fwriter = new FileWriter(file);
ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
Expand All @@ -685,12 +669,28 @@ public static File createThreadsFile() {
ThreadInfo info = threadBean.getThreadInfo(l, 100);
if (info != null) {
String threadName = info.getThreadName();
fwriter.append(StringUtils.rightPad(threadName, THREAD_INDENT_SPACE));
fwriter.append(AppUtils.formatStackTrace(info.getStackTrace(), THREAD_INDENT_SPACE, false));
fwriter.append("\n");

boolean skip = isFiltered;
if (isFiltered) {
for (StackTraceElement element : info.getStackTrace()) {
String name = element.getClassName();
if (name.startsWith("com.jumpmind.") || name.startsWith("org.jumpmind.")) {
skip = false;
}
if (name.equals(SnapshotUtil.class.getName()) || name.startsWith(UpdateService.class.getName())) {
skip = true;
break;
}
}
}

if (!skip) {
fwriter.append(StringUtils.rightPad(threadName, THREAD_INDENT_SPACE));
fwriter.append(AppUtils.formatStackTrace(info.getStackTrace(), THREAD_INDENT_SPACE, false));
fwriter.append("\n");
}
}
}

} catch (Exception e) {
log.warn("Failed to export thread information", e);
} finally {
Expand Down

0 comments on commit c5ffcfc

Please sign in to comment.