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 */); }
private static synchronized ExecutorService getExecutor() { if (clientExecutor == null) { clientExecutor = new ForkJoinPool( Runtime.getRuntime().availableProcessors(), new ForkJoinWorkerThreadFactory() { final AtomicInteger num = new AtomicInteger(); @Override public ForkJoinWorkerThread newThread(ForkJoinPool pool) { ForkJoinWorkerThread thread = defaultForkJoinWorkerThreadFactory.newThread(pool); thread.setDaemon(true); thread.setName("grpc-client-app-" + "-" + num.getAndIncrement()); return thread; } }, UncaughtExceptionHandlers.systemExit(), true /* async */); } return clientExecutor; }
@Override public void run() { Thread.currentThread().setUncaughtExceptionHandler(UncaughtExceptionHandlers.systemExit()); Application application = this.application.get(); if (runtime.getConfiguration().getArguments().getProgramName().isEmpty()) { runtime.getConfiguration().getArguments().setProgramName(application.getClass().getName()); } exitIfHelpSet(runtime.getConfiguration().getArguments()); logger.info("{}", runtime.getConfiguration().getConfig()); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { runtime.shutdown(); } }); application.run(); logger.info("Exiting"); }
/** * 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()); }
/** * 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()); }
/** * Separated out for easy overriding in tests. */ @VisibleForTesting protected ExecutorService createExecutor() { return Executors.newSingleThreadExecutor( new ThreadFactoryBuilder() .setDaemon(true) .setNameFormat("Logger channel to " + addr) .setUncaughtExceptionHandler( UncaughtExceptionHandlers.systemExit()) .build()); }
RealCommandContext() { ThreadFactory threadFactory = new ThreadFactoryBuilder() .setNameFormat("gletscher-pool-%d") .setUncaughtExceptionHandler(UncaughtExceptionHandlers.systemExit()) .build(); executor = MoreExecutors.listeningDecorator( new ThreadPoolExecutor( 4, 32, 1, TimeUnit.MINUTES, new LinkedBlockingQueue<>(1024), threadFactory)); }
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(); }