List of usage examples for java.lang Thread setDefaultUncaughtExceptionHandler
public static void setDefaultUncaughtExceptionHandler(UncaughtExceptionHandler eh)
From source file:com.arpnetworking.metrics.mad.Main.java
/** * Entry point for Metrics Aggregator Daemon (MAD). * * @param args the command line arguments *//*from w w w .j a va 2s .com*/ public static void main(final String[] args) { // Global initialization Thread.setDefaultUncaughtExceptionHandler((thread, throwable) -> { System.err.println("Unhandled exception! exception: " + throwable.toString()); throwable.printStackTrace(System.err); }); Thread.currentThread().setUncaughtExceptionHandler((thread, throwable) -> LOGGER.error() .setMessage("Unhandled exception!").setThrowable(throwable).log()); LOGGER.info().setMessage("Launching mad").log(); Runtime.getRuntime().addShutdownHook(SHUTDOWN_THREAD); System.setProperty("org.vertx.logger-delegate-factory-class-name", "org.vertx.java.core.logging.impl.SLF4JLogDelegateFactory"); // Run the tsd aggregator if (args.length != 1) { throw new RuntimeException("No configuration file specified"); } LOGGER.debug().setMessage("Loading configuration").addData("file", args[0]).log(); Optional<DynamicConfiguration> configuration = Optional.empty(); Optional<Configurator<Main, AggregatorConfiguration>> configurator = Optional.empty(); try { final File configurationFile = new File(args[0]); configurator = Optional.of(new Configurator<>(Main::new, AggregatorConfiguration.class)); configuration = Optional.of(new DynamicConfiguration.Builder().setObjectMapper(OBJECT_MAPPER) .addSourceBuilder(getFileSourceBuilder(configurationFile)) .addTrigger(new FileTrigger.Builder().setFile(configurationFile).build()) .addListener(configurator.get()).build()); configuration.get().launch(); // Wait for application shutdown SHUTDOWN_SEMAPHORE.acquire(); } catch (final InterruptedException e) { throw Throwables.propagate(e); } finally { if (configurator.isPresent()) { configurator.get().shutdown(); } if (configuration.isPresent()) { configuration.get().shutdown(); } // Notify the shutdown that we're done SHUTDOWN_SEMAPHORE.release(); } }
From source file:dk.dma.ais.utils.aisbus.AisBusLauncher.java
public static void main(String[] args) throws Exception { Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { @Override/*from w w w.j av a2 s . c o m*/ public void uncaughtException(Thread t, Throwable e) { LOG.error("Uncaught exception in thread " + t.getClass().getCanonicalName() + ": " + e.getMessage(), e); System.exit(-1); } }); new AisBusLauncher().execute(args); }
From source file:fll.subjective.SubjectiveFrame.java
public static void main(final String[] args) { LogUtils.initializeLogging();/* ww w . java2 s . c o m*/ Thread.setDefaultUncaughtExceptionHandler(new GuiExceptionHandler()); // Use cross platform look and feel so that things look right all of the // time try { UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); } catch (final ClassNotFoundException e) { LOGGER.warn("Could not find cross platform look and feel class", e); } catch (final InstantiationException e) { LOGGER.warn("Could not instantiate cross platform look and feel class", e); } catch (final IllegalAccessException e) { LOGGER.warn("Error loading cross platform look and feel", e); } catch (final UnsupportedLookAndFeelException e) { LOGGER.warn("Cross platform look and feel unsupported?", e); } try { final SubjectiveFrame frame = new SubjectiveFrame(); frame.addWindowListener(new WindowAdapter() { @Override @SuppressFBWarnings(value = { "DM_EXIT" }, justification = "Exiting from main is OK") public void windowClosing(final WindowEvent e) { System.exit(0); } @Override @SuppressFBWarnings(value = { "DM_EXIT" }, justification = "Exiting from main is OK") public void windowClosed(final WindowEvent e) { System.exit(0); } }); // should be able to watch for window closing, but hidden works frame.addComponentListener(new ComponentAdapter() { @Override @SuppressFBWarnings(value = { "DM_EXIT" }, justification = "Exiting from main is OK") public void componentHidden(final ComponentEvent e) { System.exit(0); } }); GraphicsUtils.centerWindow(frame); frame.setVisible(true); frame.promptForFile(); } catch (final Throwable e) { JOptionPane.showMessageDialog(null, "Unexpected error: " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); LOGGER.fatal("Unexpected error", e); System.exit(1); } }
From source file:org.pdfsam.App.java
public static void main(String[] args) { Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionLogger()); launch(args); }
From source file:fll.scheduler.SchedulerUI.java
public static void main(final String[] args) { LogUtils.initializeLogging();//w w w.ja v a 2s . com Thread.setDefaultUncaughtExceptionHandler(new GuiExceptionHandler()); // Use cross platform look and feel so that things look right all of the // time try { UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); } catch (final ClassNotFoundException e) { LOGGER.warn("Could not find cross platform look and feel class", e); } catch (final InstantiationException e) { LOGGER.warn("Could not instantiate cross platform look and feel class", e); } catch (final IllegalAccessException e) { LOGGER.warn("Error loading cross platform look and feel", e); } catch (final UnsupportedLookAndFeelException e) { LOGGER.warn("Cross platform look and feel unsupported?", e); } try { final SchedulerUI frame = new SchedulerUI(); frame.addWindowListener(new WindowAdapter() { @Override @SuppressFBWarnings(value = { "DM_EXIT" }, justification = "Exiting from main is OK") public void windowClosing(final WindowEvent e) { System.exit(0); } @Override @SuppressFBWarnings(value = { "DM_EXIT" }, justification = "Exiting from main is OK") public void windowClosed(final WindowEvent e) { System.exit(0); } }); // should be able to watch for window closing, but hidden works frame.addComponentListener(new ComponentAdapter() { @Override @SuppressFBWarnings(value = { "DM_EXIT" }, justification = "Exiting from main is OK") public void componentHidden(final ComponentEvent e) { System.exit(0); } }); GraphicsUtils.centerWindow(frame); frame.setVisible(true); } catch (final Exception e) { LOGGER.fatal("Unexpected error", e); JOptionPane.showMessageDialog(null, "An unexpected error occurred. Please send the log file and a description of what you were doing to the developer. Error message: " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } }
From source file:pcgen.system.Main.java
/** * @param args the command line arguments */// w ww . j av a 2 s .co m public static void main(String[] args) { Logging.log(Level.INFO, "Starting PCGen v" + PCGenPropBundle.getVersionNumber() //$NON-NLS-1$ + PCGenPropBundle.getAutobuildString()); Thread.setDefaultUncaughtExceptionHandler(new PCGenUncaughtExceptionHandler()); logSystemProps(); configFactory = new PropertyContextFactory(getConfigPath()); configFactory.registerAndLoadPropertyContext(ConfigurationSettings.getInstance()); parseCommands(args); if (startNameGen) { Component dialog = new RandomNameDialog(null, null); dialog.setVisible(true); System.exit(0); } if (exportSheet == null) { startupWithGUI(); } else { startupWithoutGUI(); shutdown(); } }
From source file:org.apache.hadoop.yarn.server.sharedcachemanager.SharedCacheManager.java
public static void main(String[] args) { Thread.setDefaultUncaughtExceptionHandler(new YarnUncaughtExceptionHandler()); StringUtils.startupShutdownMessage(SharedCacheManager.class, args, LOG); try {// w w w .j a va 2s . c o m Configuration conf = new YarnConfiguration(); SharedCacheManager sharedCacheManager = new SharedCacheManager(); ShutdownHookManager.get().addShutdownHook(new CompositeServiceShutdownHook(sharedCacheManager), SHUTDOWN_HOOK_PRIORITY); sharedCacheManager.init(conf); sharedCacheManager.start(); } catch (Throwable t) { LOG.fatal("Error starting SharedCacheManager", t); System.exit(-1); } }
From source file:org.apache.rya.export.client.MergeDriverClient.java
public static void main(final String[] args) throws ParseException, MergeConfigurationException, UnknownHostException, MergerException, java.text.ParseException, SailException, AccumuloException, AccumuloSecurityException, InferenceEngineException, RepositoryException, MalformedQueryException, UpdateExecutionException { final String log4jConfiguration = System.getProperties().getProperty("log4j.configuration"); if (StringUtils.isNotBlank(log4jConfiguration)) { final String parsedConfiguration = StringUtils.removeStart(log4jConfiguration, "file:"); final File configFile = new File(parsedConfiguration); if (configFile.exists()) { DOMConfigurator.configure(parsedConfiguration); } else {//from w ww .j av a 2s .co m BasicConfigurator.configure(); } } final MergeConfigurationCLI config = new MergeConfigurationCLI(args); try { configuration = config.createConfiguration(); } catch (final MergeConfigurationException e) { LOG.error("Configuration failed.", e); } final boolean useTimeSync = configuration.getUseNtpServer(); Optional<Long> offset = Optional.absent(); if (useTimeSync) { final String tomcat = configuration.getChildTomcatUrl(); final String ntpHost = configuration.getNtpServerHost(); try { offset = Optional .<Long>fromNullable(TimeUtils.getNtpServerAndMachineTimeDifference(ntpHost, tomcat)); } catch (final IOException e) { LOG.error("Unable to get time difference between time server: " + ntpHost + " and the server: " + tomcat, e); } } final StatementStoreFactory storeFactory = new StatementStoreFactory(configuration); try { final RyaStatementStore parentStore = storeFactory.getParentStatementStore(); final RyaStatementStore childStore = storeFactory.getChildStatementStore(); LOG.info("Starting Merge Tool"); if (configuration.getParentDBType() == ACCUMULO && configuration.getChildDBType() == ACCUMULO) { final AccumuloRyaStatementStore childAStore = (AccumuloRyaStatementStore) childStore; final AccumuloRyaStatementStore parentAStore = (AccumuloRyaStatementStore) parentStore; //do map reduce merging. //TODO: Run Merger } else { if (configuration.getMergePolicy() == TIMESTAMP) { final TimestampPolicyMergeConfiguration timeConfig = (TimestampPolicyMergeConfiguration) configuration; final Long timeOffset; if (offset.isPresent()) { timeOffset = offset.get(); } else { timeOffset = 0L; } final MemoryTimeMerger merger = new MemoryTimeMerger(parentStore, childStore, new VisibilityStatementMerger(), timeConfig.getToolStartTime(), configuration.getParentRyaInstanceName(), timeOffset); merger.runJob(); } } } catch (final Exception e) { LOG.error("Something went wrong creating a Rya Statement Store connection.", e); } Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(final Thread thread, final Throwable throwable) { LOG.error("Uncaught exception in " + thread.getName(), throwable); } }); LOG.info("Finished running Merge Tool"); System.exit(1); }
From source file:org.apache.tajo.util.JvmPauseMonitor.java
/** * Simple 'main' to facilitate manual testing of the pause monitor. * * This main function just leaks memory into a list. Running this class * with a 1GB heap will very quickly go into "GC hell" and result in * log messages about the GC pauses./*ww w .j a v a2 s . co m*/ */ public static void main(String[] args) throws Exception { Thread.setDefaultUncaughtExceptionHandler(new TajoUncaughtExceptionHandler()); new JvmPauseMonitor(new Configuration()).start(); List<String> list = Lists.newArrayList(); int i = 0; while (true) { list.add(String.valueOf(i++)); } }
From source file:org.apache.hadoop.mapreduce.v2.app.MapCollectiveAppMaster.java
public static void main(String[] args) { // Log that a modified MRAppMaster starts LOG.info("MapCollectiveAppMaster (MRAppMaster) starts."); try {/*from w w w . ja v a 2s . com*/ Thread.setDefaultUncaughtExceptionHandler(new YarnUncaughtExceptionHandler()); String containerIdStr = System.getenv(Environment.CONTAINER_ID.name()); String nodeHostString = System.getenv(Environment.NM_HOST.name()); String nodePortString = System.getenv(Environment.NM_PORT.name()); String nodeHttpPortString = System.getenv(Environment.NM_HTTP_PORT.name()); String appSubmitTimeStr = System.getenv(ApplicationConstants.APP_SUBMIT_TIME_ENV); validateInputParam(containerIdStr, Environment.CONTAINER_ID.name()); validateInputParam(nodeHostString, Environment.NM_HOST.name()); validateInputParam(nodePortString, Environment.NM_PORT.name()); validateInputParam(nodeHttpPortString, Environment.NM_HTTP_PORT.name()); validateInputParam(appSubmitTimeStr, ApplicationConstants.APP_SUBMIT_TIME_ENV); ContainerId containerId = ConverterUtils.toContainerId(containerIdStr); ApplicationAttemptId applicationAttemptId = containerId.getApplicationAttemptId(); long appSubmitTime = Long.parseLong(appSubmitTimeStr); MRAppMaster appMaster = new MapCollectiveAppMaster(applicationAttemptId, containerId, nodeHostString, Integer.parseInt(nodePortString), Integer.parseInt(nodeHttpPortString), appSubmitTime); ShutdownHookManager.get().addShutdownHook(new MRAppMasterShutdownHook(appMaster), SHUTDOWN_HOOK_PRIORITY); JobConf conf = new JobConf(new YarnConfiguration()); conf.addResource(new Path(MRJobConfig.JOB_CONF_FILE)); MRWebAppUtil.initialize(conf); String jobUserName = System.getenv(ApplicationConstants.Environment.USER.name()); conf.set(MRJobConfig.USER_NAME, jobUserName); // Do not automatically close FileSystem // objects so that in case of // SIGTERM I have a chance to write out the // job history. I'll be closing // the objects myself. conf.setBoolean("fs.automatic.close", false); initAndStartAppMaster(appMaster, conf, jobUserName); } catch (Throwable t) { LOG.fatal("Error starting MRAppMaster", t); ExitUtil.terminate(1, t); } }