com.google.common.util.concurrent.UncaughtExceptionHandlers Java Examples

The following examples show how to use com.google.common.util.concurrent.UncaughtExceptionHandlers. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LoadServer.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
ExecutorService getExecutor(int asyncThreads) {
  // TODO(carl-mastrangelo): This should not be necessary.  I don't know where this should be
  // put.  Move it somewhere else, or remove it if no longer necessary.
  // See: https://github.com/grpc/grpc-java/issues/2119
  return new ForkJoinPool(asyncThreads,
      new ForkJoinWorkerThreadFactory() {
        final AtomicInteger num = new AtomicInteger();
        @Override
        public ForkJoinWorkerThread newThread(ForkJoinPool pool) {
          ForkJoinWorkerThread thread = defaultForkJoinWorkerThreadFactory.newThread(pool);
          thread.setDaemon(true);
          thread.setName("server-worker-" + "-" + num.getAndIncrement());
          return thread;
        }
      }, UncaughtExceptionHandlers.systemExit(), true /* async */);
}
 
Example #2
Source File: LoadServer.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
ExecutorService getExecutor(int asyncThreads) {
  // TODO(carl-mastrangelo): This should not be necessary.  I don't know where this should be
  // put.  Move it somewhere else, or remove it if no longer necessary.
  // See: https://github.com/grpc/grpc-java/issues/2119
  return new ForkJoinPool(asyncThreads,
      new ForkJoinWorkerThreadFactory() {
        final AtomicInteger num = new AtomicInteger();
        @Override
        public ForkJoinWorkerThread newThread(ForkJoinPool pool) {
          ForkJoinWorkerThread thread = defaultForkJoinWorkerThreadFactory.newThread(pool);
          thread.setDaemon(true);
          thread.setName("server-worker-" + "-" + num.getAndIncrement());
          return thread;
        }
      }, UncaughtExceptionHandlers.systemExit(), true /* async */);
}
 
Example #3
Source File: WorkerMain.java    From data-transfer-project with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
  Thread.setDefaultUncaughtExceptionHandler(UncaughtExceptionHandlers.systemExit());

  WorkerMain workerMain = new WorkerMain();
  workerMain.initialize();
  workerMain.poll();

  System.exit(0);
}
 
Example #4
Source File: SingleVMMain.java    From data-transfer-project with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
  Thread.setDefaultUncaughtExceptionHandler(UncaughtExceptionHandlers.systemExit());

  SingleVMMain singleVMMain = new SingleVMMain();

  Runtime.getRuntime().addShutdownHook(new Thread(singleVMMain::shutdown));

  // TODO make number of workers configurable
  singleVMMain.initializeWorkers(1);
  singleVMMain.initializeGateway();
}
 
Example #5
Source File: IPCLoggerChannel.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Separated out for easy overriding in tests.
 */
@VisibleForTesting
protected ExecutorService createSingleThreadExecutor() {
  return Executors.newSingleThreadExecutor(
      new ThreadFactoryBuilder()
        .setDaemon(true)
        .setNameFormat("Logger channel (from single-thread executor) to " +
            addr)
        .setUncaughtExceptionHandler(
            UncaughtExceptionHandlers.systemExit())
        .build());
}
 
Example #6
Source File: IPCLoggerChannel.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Separated out for easy overriding in tests.
 */
@VisibleForTesting
protected ExecutorService createParallelExecutor() {
  return Executors.newCachedThreadPool(
      new ThreadFactoryBuilder()
          .setDaemon(true)
          .setNameFormat("Logger channel (from parallel executor) to " + addr)
          .setUncaughtExceptionHandler(
              UncaughtExceptionHandlers.systemExit())
          .build());
}
 
Example #7
Source File: IPCLoggerChannel.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Separated out for easy overriding in tests.
 */
@VisibleForTesting
protected ExecutorService createSingleThreadExecutor() {
  return Executors.newSingleThreadExecutor(
      new ThreadFactoryBuilder()
        .setDaemon(true)
        .setNameFormat("Logger channel (from single-thread executor) to " +
            addr)
        .setUncaughtExceptionHandler(
            UncaughtExceptionHandlers.systemExit())
        .build());
}
 
Example #8
Source File: IPCLoggerChannel.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Separated out for easy overriding in tests.
 */
@VisibleForTesting
protected ExecutorService createParallelExecutor() {
  return Executors.newCachedThreadPool(
      new ThreadFactoryBuilder()
          .setDaemon(true)
          .setNameFormat("Logger channel (from parallel executor) to " + addr)
          .setUncaughtExceptionHandler(
              UncaughtExceptionHandlers.systemExit())
          .build());
}
 
Example #9
Source File: WebServerRunner.java    From greenbeans with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
	Thread.currentThread().setUncaughtExceptionHandler(UncaughtExceptionHandlers.systemExit());

	maybeEnableDemo();

	Server server = new Server(PORT);

	ServletContextHandler contextHandler = new ServletContextHandler(server, "/");
	addDefaultServlet(contextHandler);

	addJerseyServlet(contextHandler);
	addCorHeadersFilter(contextHandler);

	server.start();
	server.join();
}