List of usage examples for java.lang Thread.UncaughtExceptionHandler Thread.UncaughtExceptionHandler
Thread.UncaughtExceptionHandler
From source file:org.apache.lens.server.LensServer.java
/** Registering a default uncaught exception handler. */ private static void registerDefaultExceptionHandler() { Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override/*www. j av a 2s . c om*/ public void uncaughtException(Thread t, Throwable e) { LOG.fatal("Uncaught exception in Thread " + t, e); } }); }
From source file:org.apache.hadoop.net.unix.DomainSocketWatcher.java
public DomainSocketWatcher(int interruptCheckPeriodMs, String src) throws IOException { if (loadingFailureReason != null) { throw new UnsupportedOperationException(loadingFailureReason); }/*from w w w . j a va2 s . c om*/ Preconditions.checkArgument(interruptCheckPeriodMs > 0); this.interruptCheckPeriodMs = interruptCheckPeriodMs; notificationSockets = DomainSocket.socketpair(); watcherThread.setDaemon(true); watcherThread.setName(src + " DomainSocketWatcher"); watcherThread.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(Thread thread, Throwable t) { LOG.error(thread + " terminating on unexpected exception", t); } }); watcherThread.start(); }
From source file:de.unidue.inf.is.ezdl.gframedl.EzDL.java
private static void initLogging() { System.setProperty("appDir", SystemUtils.getPropertyDir().getAbsolutePath()); URL logConfigUrl = null;//from ww w. ja v a 2 s .com File logConfigFile = new File(SystemUtils.getPropertyDir(), "/logging.properties"); if (logConfigFile.exists()) { try { logConfigUrl = logConfigFile.toURI().toURL(); } catch (MalformedURLException e) { e.printStackTrace(); } } else { logConfigUrl = EzDL.class.getResource("/log/logging.properties"); } if (logConfigUrl != null) { PropertyConfigurator.configure(logConfigUrl); } else { System.err.println("no logger config found!"); } Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable e) { logger.error("Uncaught exception in Thread " + t.getName(), e); } }); System.err.close(); }
From source file:edu.unc.lib.deposit.fcrepo3.IngestDepositTest.java
@Test public void testRunFailObjectIngest() throws Exception { when(client.ingestRaw(any(byte[].class), any(Format.class), anyString())).thenReturn(new PID("pid")) .thenReturn(new PID("pid")).thenThrow(new FedoraException("")); Thread jobThread = new Thread(job); final boolean[] exceptionCaught = new boolean[] { false }; Thread.UncaughtExceptionHandler jobFailedHandler = new Thread.UncaughtExceptionHandler() { @Override/*from w w w. jav a 2 s. co m*/ public void uncaughtException(Thread th, Throwable ex) { if (ex instanceof JobFailedException) exceptionCaught[0] = true; } }; jobThread.setUncaughtExceptionHandler(jobFailedHandler); jobThread.start(); // Start processing with a timelimit to prevent infinite wait in case of failure jobThread.join(); // Only the one successful top level pid added because of ordering verify(client).addObjectRelationship(any(PID.class), anyString(), any(PID.class)); // Failing on third ingestRaw verify(client, times(3)).ingestRaw(any(byte[].class), any(Format.class), anyString()); // Only one object with data should have been uploaded verify(client).upload(any(File.class)); // PREMIS was written verify(client, times(0)).writePremisEventsToFedoraObject(any(PremisEventLogger.class), any(PID.class)); assertTrue("Job must have been registered", jmsListener.registeredJob); assertTrue("Job must have been unregistered on failure", jmsListener.registeredJob); assertTrue("Exception must have been thrown by job", exceptionCaught[0]); }
From source file:com.thoughtworks.go.server.service.PipelineConfigServicePerformanceTest.java
private void run(Runnable runnable, int numberOfRequests, final ConcurrentHashMap<String, Boolean> results) throws InterruptedException { Boolean finalResult = true;/*from ww w .j av a 2 s . c o m*/ LOGGER.info("Tests start now!"); final ArrayList<Thread> threads = new ArrayList<>(); for (int i = 0; i < numberOfRequests; i++) { Thread t = new Thread(runnable, "pipeline" + i); threads.add(t); } for (Thread t : threads) { Thread.sleep(1000 * (new Random().nextInt(3) + 1)); t.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { public void uncaughtException(Thread t, Throwable e) { LOGGER.error("Exception " + e + " from thread " + t); results.put(t.getName(), false); } }); t.start(); } for (Thread t : threads) { int i = threads.indexOf(t); if (i == (numberOfRequests - 1)) { // takeHeapDump(dumpDir, i); } t.join(); } for (String threadId : results.keySet()) { finalResult = results.get(threadId) && finalResult; } assertThat(finalResult, is(true)); }
From source file:org.netflux.core.task.AbstractTask.java
public void start() { // TODO: Thread handling // TODO: Improve uncaught exception handling Thread taskWorker = this.getTaskWorker(); taskWorker.setName(this.getName()); taskWorker.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { public void uncaughtException(Thread thread, Throwable throwable) { String message = MessageFormat .format(AbstractTask.messages.getString("exception.uncaught.exception"), thread.getName()); AbstractTask.log.error(message, throwable); for (OutputPort outputPort : AbstractTask.this.outputPorts.values()) { outputPort.consume(Record.END_OF_DATA); }/* ww w . ja va 2 s. c om*/ } }); taskWorker.start(); }
From source file:org.apache.hadoop.hbase.security.TestSecureIPC.java
/** * Sets up a RPC Server and a Client. Does a RPC checks the result. If an exception is thrown from * the stub, this function will throw root cause of that exception. */// w ww . j a va2 s . c o m private void callRpcService(User clientUser) throws Exception { SecurityInfo securityInfoMock = Mockito.mock(SecurityInfo.class); Mockito.when(securityInfoMock.getServerPrincipal()).thenReturn(HBaseKerberosUtils.KRB_PRINCIPAL); SecurityInfo.addInfo("TestProtobufRpcProto", securityInfoMock); InetSocketAddress isa = new InetSocketAddress(HOST, 0); RpcServerInterface rpcServer = new RpcServer(null, "AbstractTestSecureIPC", Lists.newArrayList(new RpcServer.BlockingServiceAndInterface((BlockingService) SERVICE, null)), isa, serverConf, new FifoRpcScheduler(serverConf, 1)); rpcServer.start(); try (RpcClient rpcClient = RpcClientFactory.createClient(clientConf, HConstants.DEFAULT_CLUSTER_ID.toString())) { BlockingInterface stub = newBlockingStub(rpcClient, rpcServer.getListenerAddress(), clientUser); TestThread th1 = new TestThread(stub); final Throwable exception[] = new Throwable[1]; Collections.synchronizedList(new ArrayList<Throwable>()); Thread.UncaughtExceptionHandler exceptionHandler = new Thread.UncaughtExceptionHandler() { public void uncaughtException(Thread th, Throwable ex) { exception[0] = ex; } }; th1.setUncaughtExceptionHandler(exceptionHandler); th1.start(); th1.join(); if (exception[0] != null) { // throw root cause. while (exception[0].getCause() != null) { exception[0] = exception[0].getCause(); } throw (Exception) exception[0]; } } finally { rpcServer.stop(); } }
From source file:com.igormaznitsa.sciareto.ui.UiUtils.java
public static void openInSystemViewer(@Nonnull final File file) { final Runnable startEdit = new Runnable() { @Override// w w w .j ava 2 s . c o m public void run() { boolean ok = false; if (Desktop.isDesktopSupported()) { final Desktop dsk = Desktop.getDesktop(); if (dsk.isSupported(Desktop.Action.OPEN)) { try { dsk.open(file); ok = true; } catch (Throwable ex) { LOGGER.error("Can't open file in system viewer : " + file, ex);//NOI18N } } } if (!ok) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { DialogProviderManager.getInstance().getDialogProvider() .msgError("Can't open file in system viewer! See the log!");//NOI18N Toolkit.getDefaultToolkit().beep(); } }); } } }; final Thread thr = new Thread(startEdit, " MMDStartFileEdit");//NOI18N thr.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(final Thread t, final Throwable e) { LOGGER.error("Detected uncaught exception in openInSystemViewer() for file " + file, e); } }); thr.setDaemon(true); thr.start(); }
From source file:com.hijacker.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override/* w w w . j a va 2 s. c o m*/ public void uncaughtException(Thread thread, Throwable throwable) { throwable.printStackTrace(); String stackTrace = ""; stackTrace += throwable.getMessage() + '\n'; for (int i = 0; i < throwable.getStackTrace().length; i++) { stackTrace += throwable.getStackTrace()[i].toString() + '\n'; } Intent intent = new Intent(); intent.setAction("com.hijacker.SendLogActivity"); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra("exception", stackTrace); startActivity(intent); finish(); System.exit(1); } }); adapter = new MyListAdapter(); //ALWAYS BEFORE setContentView AND setup(), can't stress it enough... adapter.setNotifyOnChange(true); custom_action_adapter = new CustomActionAdapter(); custom_action_adapter.setNotifyOnChange(true); file_explorer_adapter = new FileExplorerAdapter(); file_explorer_adapter.setNotifyOnChange(true); setContentView(R.layout.activity_main); setSupportActionBar((Toolbar) findViewById(R.id.my_toolbar)); //Google AppIndex client = new GoogleApiClient.Builder(MainActivity.this).addApi(AppIndex.API).build(); //fullSetup(); new SetupTask().execute(); }
From source file:com.nikonhacker.gui.EmulatorUI.java
public static void main(String[] args) throws EmulationException, IOException, ClassNotFoundException, UnsupportedLookAndFeelException, IllegalAccessException, InstantiationException { // Workaround for JDK bug - https://code.google.com/p/nikon-firmware-tools/issues/detail?id=17 System.setProperty("java.util.Arrays.useLegacyMergeSort", "true"); if (args.length > 0) { imageFile[Constants.CHIP_FR] = new File(args[0]); if (args.length > 1) { imageFile[Constants.CHIP_TX] = new File(args[1]); }/*from ww w . ja v a 2s .co m*/ } initProgrammableTimerAnimationIcons(BUTTON_SIZE_SMALL); // a lot of calls are made from GUI in AWT thread that exits fast with no error code Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { public void uncaughtException(Thread t, Throwable e) { e.printStackTrace(); System.exit(1); } }); //Schedule a job for the event-dispatching thread: //creating and showing this application's GUI. SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); }