List of usage examples for com.google.common.util.concurrent ThreadFactoryBuilder ThreadFactoryBuilder
public ThreadFactoryBuilder()
From source file:com.google.gerrit.sshd.CommandFactoryProvider.java
@Inject CommandFactoryProvider(@CommandName(Commands.ROOT) final DispatchCommandProvider d, @GerritServerConfig final Config cfg, final WorkQueue workQueue, final SshLog l, final SshScope s, SchemaFactory<ReviewDb> sf) { dispatcher = d;/*from w ww. ja v a 2 s.com*/ log = l; sshScope = s; schemaFactory = sf; int threads = cfg.getInt("sshd", "commandStartThreads", 2); startExecutor = workQueue.createQueue(threads, "SshCommandStart"); destroyExecutor = Executors.newSingleThreadExecutor( new ThreadFactoryBuilder().setNameFormat("SshCommandDestroy-%s").setDaemon(true).build()); }
From source file:at.ac.univie.isc.asio.tool.JdbcTools.java
/** * Customize hikari configuration in place, using a jdbc settings holder. * * @param hikari origin hikari settings/* w w w. j a v a 2s .c o m*/ * @param id id of the enclosing context * @param jdbc jdbc settings * @return customized hikari configuration */ public static HikariConfig populate(final HikariConfig hikari, final String id, final Jdbc jdbc) { hikari.setCatalog(jdbc.getSchema()); hikari.setJdbcUrl(jdbc.getUrl()); hikari.setUsername(jdbc.getUsername()); hikari.setPassword(jdbc.getPassword()); if (jdbc.getDriver() != null && hikari.getDataSourceClassName() == null) { // only set the driver class if no DataSource class is given - hikari will not accept both hikari.setDriverClassName(jdbc.getDriver()); } final Properties properties = injectRequiredProperties(jdbc.getProperties(), jdbc.getUrl()); hikari.setDataSourceProperties(properties); final String poolName = Pretty.format("%s-hikari-pool", id); hikari.setPoolName(poolName); hikari.setThreadFactory(new ThreadFactoryBuilder().setNameFormat(poolName + "-thread-%d").build()); return hikari; }
From source file:org.apache.beam.runners.fnexecution.EmbeddedSdkHarness.java
@Override protected void before() throws Exception { InProcessServerFactory serverFactory = InProcessServerFactory.create(); executor = Executors.newCachedThreadPool(new ThreadFactoryBuilder().setDaemon(true).build()); ControlClientPool clientPool = MapControlClientPool.create(); FnApiControlClientPoolService clientPoolService = FnApiControlClientPoolService .offeringClientsToPool(clientPool.getSink(), GrpcContextHeaderAccessorProvider.getHeaderAccessor()); loggingServer = GrpcFnServer//from w w w.j a va 2 s.c o m .allocatePortAndCreateFor(GrpcLoggingService.forWriter(Slf4jLogWriter.getDefault()), serverFactory); dataServer = GrpcFnServer.allocatePortAndCreateFor( GrpcDataService.create(executor, OutboundObserverFactory.serverDirect()), serverFactory); controlServer = GrpcFnServer.allocatePortAndCreateFor(clientPoolService, serverFactory); InstructionRequestHandler requestHandler = EmbeddedEnvironmentFactory .create(PipelineOptionsFactory.create(), loggingServer, controlServer, clientPool.getSource()) // The EmbeddedEnvironmentFactory can only create Java environments, regardless of the // Environment that's passed to it. .createEnvironment(Environment.getDefaultInstance()).getInstructionRequestHandler(); // TODO: https://issues.apache.org/jira/browse/BEAM-4149 Worker ids cannot currently be set by // the harness. All clients have the implicit empty id for now. client = SdkHarnessClient.usingFnApiClient(requestHandler, dataServer.getService()); }
From source file:org.apache.beam.runners.fnexecution.InProcessSdkHarness.java
@Override protected void before() throws Exception { InProcessServerFactory serverFactory = InProcessServerFactory.create(); executor = Executors.newCachedThreadPool(new ThreadFactoryBuilder().setDaemon(true).build()); ControlClientPool clientPool = MapControlClientPool.create(); FnApiControlClientPoolService clientPoolService = FnApiControlClientPoolService .offeringClientsToPool(clientPool.getSink(), GrpcContextHeaderAccessorProvider.getHeaderAccessor()); loggingServer = GrpcFnServer// ww w . j a v a 2 s . com .allocatePortAndCreateFor(GrpcLoggingService.forWriter(Slf4jLogWriter.getDefault()), serverFactory); dataServer = GrpcFnServer.allocatePortAndCreateFor( GrpcDataService.create(executor, OutboundObserverFactory.serverDirect()), serverFactory); controlServer = GrpcFnServer.allocatePortAndCreateFor(clientPoolService, serverFactory); InstructionRequestHandler requestHandler = InProcessEnvironmentFactory .create(PipelineOptionsFactory.create(), loggingServer, controlServer, clientPool.getSource()) // The InProcessEnvironmentFactory can only create Java environments, regardless of the // Environment that's passed to it. .createEnvironment(Environment.getDefaultInstance()).getInstructionRequestHandler(); // TODO: https://issues.apache.org/jira/browse/BEAM-4149 Worker ids cannot currently be set by // the harness. All clients have the implicit empty id for now. client = SdkHarnessClient.usingFnApiClient(requestHandler, dataServer.getService()); }
From source file:org.apache.samza.processor.SamzaContainerController.java
/** * Creates an instance of a controller for instantiating, starting and/or stopping {@link SamzaContainer} * Requests to execute a container are submitted to the {@link ExecutorService} * * @param taskFactory Factory that be used create instances of {@link org.apache.samza.task.StreamTask} or * {@link org.apache.samza.task.AsyncStreamTask} * @param containerShutdownMs How long the Samza container should wait for an orderly shutdown of task instances * @param processorId Id of the processor * @param metricsReporterMap Map of metric reporter name and {@link MetricsReporter} instance *//*w w w . java2s.c o m*/ public SamzaContainerController(Object taskFactory, long containerShutdownMs, String processorId, Map<String, MetricsReporter> metricsReporterMap) { this.executorService = Executors.newSingleThreadExecutor( new ThreadFactoryBuilder().setNameFormat("p" + processorId + "-container-thread-%d").build()); this.taskFactory = taskFactory; this.metricsReporterMap = metricsReporterMap; if (containerShutdownMs == -1) { this.containerShutdownMs = TaskConfigJava.DEFAULT_TASK_SHUTDOWN_MS; } else { this.containerShutdownMs = containerShutdownMs; } }
From source file:com.yahoo.omid.tso.RequestProcessorImpl.java
@Inject RequestProcessorImpl(MetricsRegistry metrics, TimestampOracle timestampOracle, PersistenceProcessor persistProc, Panicker panicker, TSOServerConfig config) { this.persistProc = persistProc; this.timestampOracle = timestampOracle; this.lowWatermark = timestampOracle.getLast(); persistProc.persistLowWatermark(lowWatermark); this.hashmap = new CommitHashMap(config.getMaxItems(), lowWatermark); // Set up the disruptor thread requestRing = RingBuffer.<RequestEvent>createMultiProducer(RequestEvent.EVENT_FACTORY, 1 << 12, new BusySpinWaitStrategy()); SequenceBarrier requestSequenceBarrier = requestRing.newBarrier(); BatchEventProcessor<RequestEvent> requestProcessor = new BatchEventProcessor<RequestEvent>(requestRing, requestSequenceBarrier, this); requestRing.addGatingSequences(requestProcessor.getSequence()); requestProcessor.setExceptionHandler(new FatalExceptionHandler(panicker)); ExecutorService requestExec = Executors .newSingleThreadExecutor(new ThreadFactoryBuilder().setNameFormat("request-%d").build()); // Each processor runs on a separate thread requestExec.submit(requestProcessor); }
From source file:com.rackspacecloud.blueflood.concurrent.ThreadPoolBuilder.java
public ThreadPoolExecutor build() { return new ThreadPoolExecutor(corePoolSize, maxPoolSize, 30, TimeUnit.SECONDS, // hard code the timeout. workQueue, new ThreadFactoryBuilder().setNameFormat(name).setPriority(Thread.NORM_PRIORITY) .setUncaughtExceptionHandler(exceptionHandler).build(), rejectedHandler);/*from ww w .j a va 2s. co m*/ }
From source file:org.apache.hadoop.hive.ql.exec.spark.SparkRecordHandler.java
private ScheduledThreadPoolExecutor getMemoryAndRowLogExecutor() { ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1, new ThreadFactoryBuilder().setNameFormat("MemoryAndRowInfoLogger").setDaemon(true) .setUncaughtExceptionHandler( (Thread t, Throwable e) -> LOG.error(t + " throws exception: " + e)) .build(),// w w w . jav a 2 s. c o m new ThreadPoolExecutor.DiscardPolicy()); executor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false); return executor; }
From source file:org.nickelproject.nickel.blobStore.S3BlobStore.java
@Inject S3BlobStore(final AmazonS3 s3Client, @Named("BucketName") final String bucketName, @Named("CheckContainsThreshold") final long checkContainsThreshold, @Named("S3BlobStoreThreadCount") final int noOfThreads) { super(checkContainsThreshold); this.bucketName = bucketName; this.s3Client = s3Client; executor = Executors.newFixedThreadPool(noOfThreads, new ThreadFactoryBuilder().setDaemon(true).setNameFormat("S3BlobStore-%s").build()); }
From source file:gobblin.util.ExecutorsUtils.java
/** * Get a new {@link java.util.concurrent.ThreadFactory} that uses a {@link LoggingUncaughtExceptionHandler} * to handle uncaught exceptions and the given thread name format. * * @param logger an {@link com.google.common.base.Optional} wrapping the {@link org.slf4j.Logger} that the * {@link LoggingUncaughtExceptionHandler} uses to log uncaught exceptions thrown in threads * @param nameFormat an {@link com.google.common.base.Optional} wrapping a thread naming format * @return a new {@link java.util.concurrent.ThreadFactory} *///from www . jav a2 s .c o m public static ThreadFactory newThreadFactory(Optional<Logger> logger, Optional<String> nameFormat) { return newThreadFactory(new ThreadFactoryBuilder(), logger, nameFormat); }