List of usage examples for java.lang Thread setDefaultUncaughtExceptionHandler
public static void setDefaultUncaughtExceptionHandler(UncaughtExceptionHandler eh)
From source file:Main.java
public static void main(String[] args) { Thread t = new Thread(new MyThread()); t.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { public void uncaughtException(Thread t, Throwable e) { System.out.println(t + " throws exception: " + e); }//from w w w . j av a 2s . c om }); t.start(); }
From source file:com.joshlong.lazyblogger.Main.java
public static void main(String[] args) { try {//from w w w .j a v a 2 s .co m Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { public void uncaughtException(Thread thread, Throwable e) { LOGGER.info(ExceptionUtils.getFullStackTrace(e)); } }); new ClassPathXmlApplicationContext("integrations-context.xml").start(); LOGGER.info("Started context: "); } catch (Throwable e) { LOGGER.info(ExceptionUtils.getFullStackTrace(e)); } }
From source file:edu.jhu.hlt.concrete.ingesters.gigaword.GigawordGzProcessor.java
public static void main(String... args) { Thread.setDefaultUncaughtExceptionHandler(new LoggedUncaughtExceptionHandler()); if (args.length != 2) { LOGGER.info("This program takes 2 arguments."); LOGGER.info("First: the path to a .gz file that is part of the English Gigaword v5 corpus."); LOGGER.info("Second: the path to the output file (a .tar.gz with communication files)."); LOGGER.info("Example usage:"); LOGGER.info("{} {} {}", GigawordGzProcessor.class.getName(), "/path/to/LDC/sgml/.gz", "/path/to/out.tar.gz"); System.exit(1);//from ww w .j a va 2s. c o m } String inPathStr = args[0]; String outPathStr = args[1]; Path inPath = Paths.get(inPathStr); if (!Files.exists(inPath)) LOGGER.error("Input path {} does not exist. Try again with the right path.", inPath.toString()); Path outPath = Paths.get(outPathStr); Optional<Path> parent = Optional.ofNullable(outPath.getParent()); // lambda does not allow caught exceptions. if (parent.isPresent()) { if (!Files.exists(outPath.getParent())) { LOGGER.info("Attempting to create output directory: {}", outPath.toString()); try { Files.createDirectories(outPath); } catch (IOException e) { LOGGER.error("Caught exception creating output directory.", e); } } } GigawordDocumentConverter conv = new GigawordDocumentConverter(); Iterator<Communication> iter = conv.gzToStringIterator(inPath); try (OutputStream os = Files.newOutputStream(outPath); BufferedOutputStream bos = new BufferedOutputStream(os, 1024 * 8 * 16); GzipCompressorOutputStream gout = new GzipCompressorOutputStream(bos); TarArchiver archiver = new TarArchiver(gout);) { while (iter.hasNext()) { Communication c = iter.next(); LOGGER.info("Adding Communication {} [UUID: {}] to archive.", c.getId(), c.getUuid().getUuidString()); archiver.addEntry(new ArchivableCommunication(c)); } } catch (IOException e) { LOGGER.error("Caught IOException during output.", e); } }
From source file:alfio.config.SpringBootLauncher.java
/** * Entry point for spring boot//from w ww . j ava2s. c o m * @param args original arguments */ public static void main(String[] args) { Thread.setDefaultUncaughtExceptionHandler(new DefaultExceptionHandler()); String profiles = System.getProperty("spring.profiles.active", ""); SpringApplication application = new SpringApplication(SpringBootInitializer.class, RepositoryConfiguration.class, DataSourceConfiguration.class, WebSecurityConfig.class, MvcConfiguration.class); List<String> additionalProfiles = new ArrayList<>(); additionalProfiles.add(Initializer.PROFILE_SPRING_BOOT); if ("true".equals(System.getenv("ALFIO_LOG_STDOUT_ONLY"))) { // -> will load application-stdout.properties on top to override the logger configuration additionalProfiles.add("stdout"); } if ("true".equals(System.getenv("ALFIO_DEMO_ENABLED"))) { additionalProfiles.add(Initializer.PROFILE_DEMO); } if ("true".equals(System.getenv("ALFIO_JDBC_SESSION_ENABLED"))) { additionalProfiles.add(Initializer.PROFILE_JDBC_SESSION); } application.setAdditionalProfiles(additionalProfiles.toArray(new String[additionalProfiles.size()])); ConfigurableApplicationContext applicationContext = application.run(args); ConfigurableEnvironment environment = applicationContext.getEnvironment(); log.info("profiles: requested {}, active {}", profiles, String.join(", ", (CharSequence[]) environment.getActiveProfiles())); if ("true".equals(System.getProperty("startDBManager"))) { launchHsqlGUI(); } }
From source file:edu.jhu.hlt.concrete.ingesters.webposts.WebPostIngesterRunner.java
/** * @param args//from ww w . ja v a 2 s. co m */ public static void main(String... args) { Thread.setDefaultUncaughtExceptionHandler(new LoggedUncaughtExceptionHandler()); WebPostIngesterRunner run = new WebPostIngesterRunner(); JCommander jc = new JCommander(run, args); jc.setProgramName(WebPostIngesterRunner.class.getSimpleName()); if (run.delegate.help) { jc.usage(); } try { Path outpath = Paths.get(run.delegate.outputPath); IngesterParameterDelegate.prepare(outpath); WebPostIngester ing = new WebPostIngester(); Path outWithExt = outpath.resolve("webposts.tar.gz"); if (Files.exists(outWithExt)) { if (!run.delegate.overwrite) { LOGGER.info("File: {} exists and overwrite disabled. Not running.", outWithExt.toString()); return; } else { Files.delete(outWithExt); } } try (OutputStream os = Files.newOutputStream(outWithExt); GzipCompressorOutputStream gout = new GzipCompressorOutputStream(os); TarArchiver arch = new TarArchiver(gout)) { for (String pstr : run.delegate.paths) { LOGGER.debug("Running on file: {}", pstr); Path p = Paths.get(pstr); new ExistingNonDirectoryFile(p); try { Communication next = ing.fromCharacterBasedFile(p); arch.addEntry(new ArchivableCommunication(next)); } catch (IngestException e) { LOGGER.error("Error processing file: " + pstr, e); } } } } catch (NotFileException | IOException e) { LOGGER.error("Caught exception processing.", e); } }
From source file:edu.jhu.hlt.concrete.ingesters.bolt.BoltIngesterRunner.java
/** * @param args//from ww w .j a va2 s . c o m */ public static void main(String... args) { Thread.setDefaultUncaughtExceptionHandler(new LoggedUncaughtExceptionHandler()); BoltIngesterRunner run = new BoltIngesterRunner(); JCommander jc = new JCommander(run, args); jc.setProgramName(BoltIngesterRunner.class.getSimpleName()); if (run.delegate.help) { jc.usage(); } try { Path outpath = Paths.get(run.delegate.outputPath); IngesterParameterDelegate.prepare(outpath); BoltForumPostIngester ing = new BoltForumPostIngester(); Path outWithExt = outpath.resolve("bolt.tar.gz"); if (Files.exists(outWithExt)) { if (!run.delegate.overwrite) { LOGGER.info("File: {} exists and overwrite disabled. Not running.", outWithExt.toString()); return; } else { Files.delete(outWithExt); } } try (OutputStream os = Files.newOutputStream(outWithExt); GzipCompressorOutputStream gout = new GzipCompressorOutputStream(os); TarArchiver arch = new TarArchiver(gout)) { for (Path p : run.delegate.findFilesInPaths()) { LOGGER.debug("Running on file: {}", p); new ExistingNonDirectoryFile(p); try { Communication next = ing.fromCharacterBasedFile(p); arch.addEntry(new ArchivableCommunication(next)); } catch (IngestException e) { LOGGER.error("Error processing file: " + p, e); } } } } catch (NotFileException | IOException e) { LOGGER.error("Caught exception processing.", e); } }
From source file:edu.jhu.hlt.concrete.ingesters.alnc.ALNCIngesterRunner.java
/** * @param args/*w w w . jav a2s . c om*/ */ public static void main(String... args) { Thread.setDefaultUncaughtExceptionHandler(new LoggedUncaughtExceptionHandler()); ALNCIngesterRunner run = new ALNCIngesterRunner(); JCommander jc = new JCommander(run, args); jc.setProgramName(ALNCIngesterRunner.class.getSimpleName()); if (run.delegate.help) { jc.usage(); } try { Path outpath = Paths.get(run.delegate.outputPath); IngesterParameterDelegate.prepare(outpath); for (String pstr : run.delegate.paths) { LOGGER.debug("Running on file: {}", pstr); Path p = Paths.get(pstr); new ExistingNonDirectoryFile(p); Path outWithExt = outpath.resolve(p.getFileName() + ".tar.gz"); if (Files.exists(outWithExt)) { if (!run.delegate.overwrite) { LOGGER.info("File: {} exists and overwrite disabled. Not running.", outWithExt.toString()); continue; } else { Files.delete(outWithExt); } } try (ALNCIngester ing = new ALNCIngester(p); OutputStream os = Files.newOutputStream(outWithExt); GzipCompressorOutputStream gout = new GzipCompressorOutputStream(os); TarArchiver arch = new TarArchiver(gout)) { Iterator<Communication> iter = ing.iterator(); while (iter.hasNext()) { Communication c = iter.next(); LOGGER.debug("Got comm: {}", c.getId()); arch.addEntry(new ArchivableCommunication(c)); } } catch (IngestException e) { LOGGER.error("Caught exception processing path: " + pstr, e); } } } catch (NotFileException | IOException e) { LOGGER.error("Caught exception processing.", e); } }
From source file:edu.jhu.hlt.concrete.gigaword.expt.ConvertGigawordDocuments.java
/** * @param args/*from w w w . j a v a 2 s .c o m*/ */ public static void main(String... args) { Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable e) { logger.error("Thread {} caught unhandled exception.", t.getName()); logger.error("Unhandled exception.", e); } }); if (args.length != 2) { logger.info("Usage: {} {} {}", GigawordConcreteConverter.class.getName(), "path/to/expt/file", "path/to/out/folder"); System.exit(1); } String exptPathStr = args[0]; String outPathStr = args[1]; // Verify path points to something. Path exptPath = Paths.get(exptPathStr); if (!Files.exists(exptPath)) { logger.error("File: {} does not exist. Re-run with the correct path to " + " the experiment 2 column file. See README.md."); System.exit(1); } logger.info("Experiment map located at: {}", exptPathStr); // Create output dir if not yet created. Path outPath = Paths.get(outPathStr); if (!Files.exists(outPath)) { logger.info("Creating directory: {}", outPath.toString()); try { Files.createDirectories(outPath); } catch (IOException e) { logger.error("Caught an IOException when creating output dir.", e); System.exit(1); } } logger.info("Output directory located at: {}", outPathStr); // Read in expt map. See README.md. Map<String, Set<String>> exptMap = null; try (Reader r = ExperimentUtils.createReader(exptPath); BufferedReader br = new BufferedReader(r)) { exptMap = ExperimentUtils.createFilenameToIdMap(br); } catch (IOException e) { logger.error("Caught an IOException when creating expt map.", e); System.exit(1); } // Start a timer. logger.info("Gigaword -> Concrete beginning."); StopWatch sw = new StopWatch(); sw.start(); // Iterate over expt map. exptMap.entrySet() // .parallelStream() .forEach(p -> { final String pathStr = p.getKey(); final Set<String> ids = p.getValue(); final Path lp = Paths.get(pathStr); logger.info("Converting path: {}", pathStr); // Get the file name and immediate folder it is under. int nElements = lp.getNameCount(); Path fileName = lp.getName(nElements - 1); Path subFolder = lp.getName(nElements - 2); String newFnStr = fileName.toString().split("\\.")[0] + ".tar"; // Mirror folders in output dir. Path localOutFolder = outPath.resolve(subFolder); Path localOutPath = localOutFolder.resolve(newFnStr); // Create output subfolders. if (!Files.exists(localOutFolder) && !Files.isDirectory(localOutFolder)) { logger.info("Creating out file: {}", localOutFolder.toString()); try { Files.createDirectories(localOutFolder); } catch (IOException e) { throw new RuntimeException("Caught an IOException when creating output dir.", e); } } // Iterate over communications. Iterator<Communication> citer; try (OutputStream os = Files.newOutputStream(localOutPath); BufferedOutputStream bos = new BufferedOutputStream(os); Archiver archiver = new TarArchiver(bos);) { citer = new ConcreteGigawordDocumentFactory().iterator(lp); while (citer.hasNext()) { Communication c = citer.next(); String cId = c.getId(); // Document ID must be in the set. Remove. boolean wasInSet = ids.remove(cId); if (!wasInSet) { // Some IDs are duplicated in Gigaword. // See ERRATA. logger.debug( "ID: {} was parsed from path: {}, but was not in the experiment map. Attempting to remove dupe.", cId, pathStr); // Attempt to create a duplicate id (append .duplicate to the id). // Then, try to remove again. String newId = RepairDuplicateIDs.repairDuplicate(cId); boolean dupeRemoved = ids.remove(newId); // There are not nested duplicates, so this should never fire. if (!dupeRemoved) { logger.info("Failed to remove dupe."); return; } else // Modify the communication ID to the unique version. c.setId(newId); } archiver.addEntry(new ArchivableCommunication(c)); } logger.info("Finished path: {}", pathStr); } catch (ConcreteException ex) { logger.error("Caught ConcreteException during Concrete mapping.", ex); logger.error("Path: {}", pathStr); } catch (IOException e) { logger.error("Error archiving communications.", e); logger.error("Path: {}", localOutPath.toString()); } }); sw.stop(); logger.info("Finished."); Minutes m = new Duration(sw.getTime()).toStandardMinutes(); logger.info("Runtime: Approximately {} minutes.", m.getMinutes()); }
From source file:edu.jhu.hlt.concrete.ingesters.annotatednyt.AnnotatedNYTIngesterRunner.java
/** * @param args/* w w w . ja va 2s . c o m*/ */ public static void main(String... args) { Thread.setDefaultUncaughtExceptionHandler(new LoggedUncaughtExceptionHandler()); AnnotatedNYTIngesterRunner run = new AnnotatedNYTIngesterRunner(); JCommander jc = new JCommander(run, args); jc.setProgramName(AnnotatedNYTIngesterRunner.class.getSimpleName()); if (run.delegate.help) { jc.usage(); } try { Path outpath = Paths.get(run.delegate.outputPath); IngesterParameterDelegate.prepare(outpath); NYTCorpusDocumentParser parser = new NYTCorpusDocumentParser(); for (String pstr : run.delegate.paths) { LOGGER.debug("Running on file: {}", pstr); Path p = Paths.get(pstr); new ExistingNonDirectoryFile(p); int nPaths = p.getNameCount(); Path year = p.getName(nPaths - 2); Path outWithExt = outpath.resolve(year.toString() + p.getFileName()); if (Files.exists(outWithExt)) { if (!run.delegate.overwrite) { LOGGER.info("File: {} exists and overwrite disabled. Not running.", outWithExt.toString()); continue; } else { Files.delete(outWithExt); } } try (InputStream is = Files.newInputStream(p); BufferedInputStream bin = new BufferedInputStream(is); TarGzArchiveEntryByteIterator iter = new TarGzArchiveEntryByteIterator(bin); OutputStream os = Files.newOutputStream(outWithExt); GzipCompressorOutputStream gout = new GzipCompressorOutputStream(os); TarArchiver arch = new TarArchiver(gout)) { Iterable<byte[]> able = () -> iter; StreamSupport.stream(able.spliterator(), false).map(ba -> parser.fromByteArray(ba, false)) .map(doc -> new AnnotatedNYTDocument(doc)) .map(and -> new CommunicationizableAnnotatedNYTDocument(and).toCommunication()) .forEach(comm -> { try { arch.addEntry(new ArchivableCommunication(comm)); } catch (IOException e) { LOGGER.error("Caught exception processing file: " + pstr, e); } }); } } } catch (NotFileException | IOException e) { LOGGER.error("Caught exception processing.", e); } }
From source file:com.varaneckas.hawkscope.Launcher.java
/** * Application bootstrapper//from w w w .j ava2s. co m * * @param args Command line arguments */ public static void main(final String[] args) { log.info(Version.formatFullString()); try { ConfigurationFactory.getConfigurationFactory(args).getConfiguration(); ModularAuthenticator.register(); Thread.setDefaultUncaughtExceptionHandler(WindowFactory.getUncaughtExceptionHandler()); WindowFactory.initialize(); } catch (final Throwable e) { log.fatal("Failed starting Hawkscope", e); } preload(); final GlobalHotkeyManager keyman = GlobalHotkeyManager.getInstance(); if (keyman != null) { keyman.configure(); } TrayManager.getInstance().load(); }