List of usage examples for com.google.common.util.concurrent ThreadFactoryBuilder ThreadFactoryBuilder
public ThreadFactoryBuilder()
From source file:org.metaservice.kryo.KryoClientUtil.java
public Client startClient(Listener listener) throws IOException { int size1 = 31457280; int size2 = 180000; LOGGER.info("Starting Client with sizes {}/{}", size1, size2); Client client = new Client(size1, size2); new KryoInitializer().initialize(client.getKryo()); ThreadFactoryBuilder builder = new ThreadFactoryBuilder(); builder.setNameFormat("threaded_listener_thread_%d"); client.addListener(//from w w w . j a v a 2 s .c om new Listener.ThreadedListener(listener, Executors.newSingleThreadExecutor(builder.build()))); client.start(); int timeout = 5000; int retries = 0; while (!client.isConnected()) { try { client.connect(timeout, "127.0.0.1", 54555/*, 54777*/); retries++; } catch (IOException e) { if (retries > 10) { LOGGER.error("stopping to retry ", e); throw e; } else { try { LOGGER.info("connection failed, retrying in 3 seconds"); Thread.sleep(3000); } catch (InterruptedException e1) { e1.printStackTrace(); } } } } return client; }
From source file:org.geoserver.cluster.hazelcast.ReloadHzSynchronizer.java
public ReloadHzSynchronizer(HzCluster cluster, GeoServer gs) { super(cluster, gs); ThreadFactory threadFactory = new ThreadFactoryBuilder().setDaemon(true) .setNameFormat("Hz-GeoServer-Reload-%d").build(); RejectedExecutionHandler rejectionHandler = new ThreadPoolExecutor.DiscardPolicy(); // a thread pool executor operating out of a blocking queue with maximum of 1 element, which // discards execute requests if the queue is full reloadService = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(1), threadFactory, rejectionHandler); }
From source file:org.sonar.server.platform.db.migration.DatabaseMigrationExecutorServiceImpl.java
public DatabaseMigrationExecutorServiceImpl() { super(Executors.newSingleThreadExecutor( new ThreadFactoryBuilder().setDaemon(false).setNameFormat("DB_migration-%d").build())); }
From source file:com.amazonaws.services.kinesis.producer.FileAgeManager.java
FileAgeManager() { this(Executors.newScheduledThreadPool(1, new ThreadFactoryBuilder().setDaemon(true).setNameFormat("KP-FileMaintenance-%04d").build())); }
From source file:de.ks.flatadocdb.TempRepository.java
@Override protected void before() throws Throwable { path = Paths.get(StandardSystemProperty.JAVA_IO_TMPDIR.value(), "testRepository"); new DeleteDir(path).delete(); metaModel = new MetaModel(); repository = new Repository(path); repository.initialize(metaModel,/* w w w . ja v a2 s . co m*/ Executors.newSingleThreadExecutor(new ThreadFactoryBuilder().setDaemon(true).build())); }
From source file:org.sonar.server.health.HealthStateRefresherExecutorServiceImpl.java
public HealthStateRefresherExecutorServiceImpl() { super(Executors.newSingleThreadScheduledExecutor( new ThreadFactoryBuilder().setDaemon(false).setNameFormat("health_state_refresh-%d").build())); }
From source file:org.sonar.server.platform.db.migrations.PlatformDatabaseMigrationExecutorServiceImpl.java
public PlatformDatabaseMigrationExecutorServiceImpl() { super(Executors.newSingleThreadExecutor( new ThreadFactoryBuilder().setDaemon(false).setNameFormat("DB_migration-%d").build())); }
From source file:org.graylog2.shared.bindings.SchedulerBindings.java
@Override protected void configure() { // TODO Add instrumentation to ExecutorService and ThreadFactory final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(SCHEDULED_THREADS_POOL_SIZE, new ThreadFactoryBuilder().setNameFormat("scheduled-%d").setDaemon(false) .setUncaughtExceptionHandler(new Tools.LogUncaughtExceptionHandler( LoggerFactory.getLogger("org.graylog2.scheduler.Scheduler"))) .build());//from w w w . ja v a2 s . c om bind(ScheduledExecutorService.class).annotatedWith(Names.named("scheduler")).toInstance(scheduler); // TODO Add instrumentation to ExecutorService and ThreadFactory final ScheduledExecutorService daemonScheduler = Executors .newScheduledThreadPool(SCHEDULED_THREADS_POOL_SIZE, new ThreadFactoryBuilder().setNameFormat("scheduled-daemon-%d").setDaemon(true) .setUncaughtExceptionHandler(new Tools.LogUncaughtExceptionHandler( LoggerFactory.getLogger("org.graylog2.scheduler.DaemonScheduler"))) .build()); bind(ScheduledExecutorService.class).annotatedWith(Names.named("daemonScheduler")) .toInstance(daemonScheduler); bind(Periodicals.class).toInstance(new Periodicals(scheduler, daemonScheduler)); }
From source file:ch.petikoch.examples.mvvm_rxjava.example8.Example_8_Model.java
public Observable<LogRow> getLogs() { SerializedSubject<LogRow, LogRow> subject = new SerializedSubject<>(PublishSubject.create()); ThreadFactory threadFactory = new ThreadFactoryBuilder().setDaemon(true) .setNameFormat(Example_8_Model.class.getSimpleName() + "-thread-%d").build(); final ExecutorService executorService = Executors .newFixedThreadPool(Runtime.getRuntime().availableProcessors(), threadFactory); IntStream.range(1, Runtime.getRuntime().availableProcessors() + 1).forEach(value -> { executorService.submit(() -> { SysOutUtils.sysout(/*from w w w.j a v a 2 s . c o m*/ Thread.currentThread().getName() + " will briefly start creating lots of log rows..."); VariousUtils.sleep(1000); long incrementingNumber = 1; while (true) { subject.onNext(new LogRow(DateTimeFormatter.ISO_DATE_TIME.format(LocalDateTime.now()), "Status " + Integer.toString(ThreadLocalRandom.current().nextInt(1, 5)), "Action " + incrementingNumber + " from " + Thread.currentThread().getName())); } }); }); return subject; }
From source file:com.cloudera.oryx.common.parallel.ExecutorUtils.java
public static ExecutorService buildExecutor(String name, int parallelism) { ThreadFactory factory = new ThreadFactoryBuilder().setNameFormat(name + "-%d").setDaemon(true).build(); log.info("Executing {} with parallelism {}", name, parallelism); return Executors.newFixedThreadPool(parallelism, factory); }