List of usage examples for java.util.concurrent Executors newCachedThreadPool
public static ExecutorService newCachedThreadPool(ThreadFactory threadFactory)
From source file:com.reactivetechnologies.platform.rest.client.AsyncClientHandlerFactoryBean.java
@PostConstruct private void init() { threads = Executors.newCachedThreadPool(new ThreadFactory() { private int n = 0; @Override/* ww w . jav a 2s . co m*/ public Thread newThread(Runnable r) { Thread t = new Thread(r, "REST-AsyncClientHandler-" + (n++)); t.setDaemon(true); return t; } }); }
From source file:com.espertech.esper.epl.metric.MetricsExecutorThreaded.java
/** * Ctor./* w ww. ja va 2 s .co m*/ * @param engineURI engine URI */ public MetricsExecutorThreaded(final String engineURI) { ThreadFactory threadFactory = new ThreadFactory() { AtomicInteger count = new AtomicInteger(0); public Thread newThread(Runnable r) { String uri = engineURI; if (engineURI == null) { uri = "default"; } Thread t = new Thread(r); t.setName("com.espertech.esper.MetricReporting-" + uri + "-" + count.getAndIncrement()); t.setDaemon(true); return t; } }; threadPool = Executors.newCachedThreadPool(threadFactory); }
From source file:com.taobao.tair.comm.TairClientFactory.java
public TairClientFactory() { ioConnector = new SocketConnector(processorCount, Executors.newCachedThreadPool(CONNECTOR_TFACTORY)); }
From source file:io.selendroid.server.SelendroidStandaloneServer.java
/** * for testing only/*from w w w . jav a 2s. c om*/ * * @throws AndroidSdkException */ protected SelendroidStandaloneServer(SelendroidConfiguration configuration, SelendroidStandaloneDriver driver) throws AndroidSdkException { this.configuration = configuration; this.driver = driver; NamingThreadFactory namingThreadFactory = new NamingThreadFactory(Executors.defaultThreadFactory(), "selendroid-standalone-handler"); webServer = WebServers.createWebServer(Executors.newCachedThreadPool(namingThreadFactory), new InetSocketAddress(configuration.getPort()), URI.create("http://127.0.0.1" + (configuration.getPort() == 80 ? "" : (":" + configuration.getPort())) + "/")); init(); }
From source file:org.apache.asterix.experiment.client.StatisticsQueryGenerator.java
public StatisticsQueryGenerator(StatisticsQueryGeneratorConfig config) { threadPool = Executors.newCachedThreadPool(new ThreadFactory() { private final AtomicInteger count = new AtomicInteger(); @Override/*from w w w.j ava2 s. c o m*/ public Thread newThread(Runnable r) { int tid = count.getAndIncrement(); Thread t = new Thread(r, "DataGeneratorThread: " + tid); t.setDaemon(true); return t; } }); this.config = config; }
From source file:com.netflix.curator.framework.recipes.shared.TestSharedCount.java
@Test public void testMultiClients() throws Exception { final int CLIENT_QTY = 5; List<Future<List<Integer>>> futures = Lists.newArrayList(); final List<CuratorFramework> clients = new CopyOnWriteArrayList<CuratorFramework>(); try {/* w w w. ja va2 s . c o m*/ final CountDownLatch startLatch = new CountDownLatch(CLIENT_QTY); final Semaphore semaphore = new Semaphore(0); ExecutorService service = Executors .newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("Test-%d").build()); for (int i = 0; i < CLIENT_QTY; ++i) { Future<List<Integer>> future = service.submit(new Callable<List<Integer>>() { @Override public List<Integer> call() throws Exception { final List<Integer> countList = Lists.newArrayList(); CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1)); clients.add(client); client.start(); SharedCount count = new SharedCount(client, "/count", 10); final CountDownLatch latch = new CountDownLatch(1); count.addListener(new SharedCountListener() { @Override public void countHasChanged(SharedCountReader sharedCount, int newCount) throws Exception { if (newCount < 0) { latch.countDown(); } else { countList.add(newCount); } semaphore.release(); } @Override public void stateChanged(CuratorFramework client, ConnectionState newState) { } }); count.start(); startLatch.countDown(); latch.await(); return countList; } }); futures.add(future); } CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1)); clients.add(client); client.start(); Assert.assertTrue(startLatch.await(10, TimeUnit.SECONDS)); SharedCount count = new SharedCount(client, "/count", 10); count.start(); List<Integer> countList = Lists.newArrayList(); Random random = new Random(); for (int i = 0; i < 100; ++i) { Thread.sleep(random.nextInt(10)); int next = random.nextInt(100); countList.add(next); count.setCount(next); Assert.assertTrue(semaphore.tryAcquire(CLIENT_QTY, 10, TimeUnit.SECONDS)); } count.setCount(-1); for (Future<List<Integer>> future : futures) { List<Integer> thisCountList = future.get(); Assert.assertEquals(thisCountList, countList); } } finally { for (CuratorFramework client : clients) { IOUtils.closeQuietly(client); } } }
From source file:natalia.dymnikova.util.ThreadPoolBeans.java
private ExecutorService commonPurposeExecutor0() { final ExecutorService executor = Executors.newCachedThreadPool( new ThreadFactoryBuilder().setNameFormat("common-purpose-%03d").setDaemon(true).build()); log.debug("Constructed common purpose executor {}", executor); return executor; }
From source file:fi.jumi.launcher.JumiLauncherBuilder.java
protected ExecutorService createActorsThreadPool() { return Executors.newCachedThreadPool(new PrefixedThreadFactory("jumi-launcher-")); }
From source file:org.elasticsoftware.elasticactors.http.actors.HttpService.java
@PostConstruct public void init() { ExecutorService bossExecutor = Executors.newCachedThreadPool(Executors.defaultThreadFactory()); ExecutorService workerExecutor = Executors.newCachedThreadPool(Executors.defaultThreadFactory()); int workers = Runtime.getRuntime().availableProcessors(); NioServerSocketChannelFactory channelFactory = new NioServerSocketChannelFactory(bossExecutor, workerExecutor, workers);/*from ww w . j ava2s . co m*/ httpServer = new HttpServer(channelFactory, this, actorSystem, configuration.getProperty(this.getClass(), "listenPort", Integer.class, 8080)); httpServer.init(); }
From source file:com.hellblazer.jackal.configuration.PartitionControllerConfig.java
protected ExecutorService controllerDispatchers() { final int id = partitionIdentity.id; return Executors.newCachedThreadPool(new ThreadFactory() { int count = 0; @Override//from ww w . ja va2 s . c o m public Thread newThread(Runnable target) { Thread t = new Thread(target, String.format("Partition Controller Dispatcher[%s]", count++, id)); t.setDaemon(true); t.setUncaughtExceptionHandler(new UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable e) { log.error(String.format("Exception on %s", t), e); } }); return t; } }); }