本文整理汇总了Java中com.google.common.util.concurrent.UncaughtExceptionHandlers类的典型用法代码示例。如果您正苦于以下问题:Java UncaughtExceptionHandlers类的具体用法?Java UncaughtExceptionHandlers怎么用?Java UncaughtExceptionHandlers使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UncaughtExceptionHandlers类属于com.google.common.util.concurrent包,在下文中一共展示了UncaughtExceptionHandlers类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getExecutor
import com.google.common.util.concurrent.UncaughtExceptionHandlers; //导入依赖的package包/类
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 */);
}
示例2: getExecutor
import com.google.common.util.concurrent.UncaughtExceptionHandlers; //导入依赖的package包/类
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;
}
示例3: run
import com.google.common.util.concurrent.UncaughtExceptionHandlers; //导入依赖的package包/类
@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");
}
示例4: createSingleThreadExecutor
import com.google.common.util.concurrent.UncaughtExceptionHandlers; //导入依赖的package包/类
/**
* 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());
}
示例5: createParallelExecutor
import com.google.common.util.concurrent.UncaughtExceptionHandlers; //导入依赖的package包/类
/**
* 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());
}
示例6: createExecutor
import com.google.common.util.concurrent.UncaughtExceptionHandlers; //导入依赖的package包/类
/**
* 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());
}
示例7: RealCommandContext
import com.google.common.util.concurrent.UncaughtExceptionHandlers; //导入依赖的package包/类
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));
}
示例8: main
import com.google.common.util.concurrent.UncaughtExceptionHandlers; //导入依赖的package包/类
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();
}