/** * @return Name of file containing thread dump * @throws Exception if file cannot be written */ public static String threadDump() throws Exception { return threadDump(new File(".")); //$NON-NLS-1$ }
/** * @param basedir {@link File} Base directory * @return Name of file containing thread dump * @throws Exception if file cannot we written */ public static String threadDump(File basedir) throws Exception { SimpleDateFormat timestampFormat = new SimpleDateFormat("yyyyMMdd_hhmmss_SSS"); String stamp = timestampFormat.format(new Date()); File temp = new File(basedir,"thread_dump_"+stamp+".log"); final String path = temp.getPath(); try (FileOutputStream fos = new FileOutputStream(temp); OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fos, StandardCharsets.UTF_8); BufferedWriter bufferedWriter = new BufferedWriter(outputStreamWriter)) { writeThreadDump(bufferedWriter); } return path; }
String s = ThreadDumper.threadDump(); JOptionPane.showMessageDialog(null, "Created "+s, "ThreadDump", JOptionPane.INFORMATION_MESSAGE); } catch (Exception ex) { // NOSONAR We show cause in message