Java Code Examples for com.google.common.util.concurrent.ThreadFactoryBuilder#setNameFormat()
The following examples show how to use
com.google.common.util.concurrent.ThreadFactoryBuilder#setNameFormat() .
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: ThreadFactories.java From caravan with Apache License 2.0 | 5 votes |
public static ThreadFactory newDaemonThreadFactory(String nameFormat) { ThreadFactoryBuilder builder = new ThreadFactoryBuilder(); builder.setDaemon(true); if (!StringValues.isNullOrWhitespace(nameFormat)) builder.setNameFormat(nameFormat); return builder.build(); }
Example 2
Source File: ExecutorsUtils.java From incubator-gobblin with Apache License 2.0 | 5 votes |
private static ThreadFactory newThreadFactory(ThreadFactoryBuilder builder, Optional<Logger> logger, Optional<String> nameFormat) { if (nameFormat.isPresent()) { builder.setNameFormat(nameFormat.get()); } return builder.setUncaughtExceptionHandler(new LoggingUncaughtExceptionHandler(logger)).build(); }
Example 3
Source File: Paralleler.java From myrrix-recommender with Apache License 2.0 | 5 votes |
/** * Run {@link Processor}, in as many threads as available cores, on values. * * @throws ExecutionException if any execution fails */ public void runInParallel() throws InterruptedException, ExecutionException { ThreadFactoryBuilder builder = new ThreadFactoryBuilder(); if (name != null) { builder.setNameFormat(name + "-%s"); } int numCores = Runtime.getRuntime().availableProcessors(); ExecutorService executor = Executors.newFixedThreadPool(numCores, builder.build()); try { runInParallel(executor, numCores); } finally { executor.shutdownNow(); } }
Example 4
Source File: ThreadUtils.java From yuzhouwan with Apache License 2.0 | 4 votes |
private static ThreadFactory buildThreadFactory(String poolName, Boolean isDaemon) { ThreadFactoryBuilder threadFactoryBuilder = new ThreadFactoryBuilder(); if (!StrUtils.isEmpty(poolName)) threadFactoryBuilder.setNameFormat("[".concat(poolName).concat("]-%d")); if (isDaemon != null) threadFactoryBuilder.setDaemon(isDaemon); return threadFactoryBuilder.build(); }