List of usage examples for java.util.concurrent Executors newFixedThreadPool
public static ExecutorService newFixedThreadPool(int nThreads, ThreadFactory threadFactory)
From source file:Main.java
public static ExecutorService newFixedThreadPool(String name, int numThreads, int maxPoolSize, int keepAliveTimeInSeconds) { LinkedBlockingQueue<Runnable> lbq = new LinkedBlockingQueue<Runnable>(); ThreadFactory tf = newNamedThreadFactory(name); ThreadPoolExecutor tpe = new ThreadPoolExecutor(numThreads, maxPoolSize, keepAliveTimeInSeconds, TimeUnit.SECONDS, lbq, tf); return Executors.newFixedThreadPool(numThreads, tpe.getThreadFactory()); }
From source file:Main.java
/** * Creates a thread pool that reuses a fixed number of threads operating off a shared unbounded queue, using the * provided ThreadFactory to create new threads when needed. At any point, at most {@code nThreads} threads will be * active processing tasks. If additional tasks are submitted when all threads are active, they will wait in the * queue until a thread is available. If any thread terminates due to a failure during execution prior to shutdown, * a new one will take its place if needed to execute subsequent tasks. The threads in the pool will exist until it * is explicitly {@link ExecutorService#shutdown shutdown}. * * @param nThreads/*from www. j a va 2 s. c om*/ * the number of threads in the pool * @param name * the name of the new thread * @return the newly created thread pool * @throws NullPointerException * if threadFactory is null * @throws IllegalArgumentException * if {@code nThreads <= 0} */ public static final ExecutorService buildNewFixedThreadExecutor(int nThreads, final String name) { return Executors.newFixedThreadPool(nThreads, getThreadFactory(name)); }
From source file:io.dyn.core.NonBlockingTaskExecutor.java
public NonBlockingTaskExecutor(String name, int internalPoolSize) { executor = Executors.newFixedThreadPool(internalPoolSize, Tasks.newThreadFactory(name)); }
From source file:bad.robot.pingpong.server.PingIntegrationTest.java
@Before public void start() throws IOException { server = new SimpleServer(Executors.newFixedThreadPool(5, new ObservableThreadFactory(createThreadSafeCounterMaintainingInvariant()))); server.start();/*from ww w . j av a 2 s . c o m*/ }
From source file:com.webbfontaine.valuewebb.irms.factory.risk.RiskActionFactory.java
private static ExecutorService getExecutorService() { return Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors(), new BasicThreadFactory.Builder().namingPattern("RiskRuleHandler-%d") .uncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable e) { LOGGER.error("", e); }//from w w w . ja va 2 s . co m }).build()); }
From source file:com.sm.connector.client.PartitionClient.java
public T execute(List<RemoteClientImpl> list, int batchSize) { logger.info("execute " + filename + " threads " + list.size() + " invoker " + invoker.toString()); int noOfThread = list.size(); //List<RemoteClientImpl> list = createClients( urls); //CountDownLatch countDownLatch = new CountDownLatch(noOfThread); ExecutorService executor = Executors.newFixedThreadPool(noOfThread, new ThreadPoolFactory("Partition")); Aggregate<T> aggregate = null; try {/* ww w . j a v a 2s . c o m*/ aggregate = (Aggregate<T>) QueryUtils.createInstance(tClass); } catch (Exception ex) { throw new RuntimeException(ex.getMessage(), ex); } List<Future<Aggregate<T>>> results = new ArrayList<Future<Aggregate<T>>>(noOfThread); for (int i = 0; i < noOfThread; i++) { try { Aggregate<T> ft = (Aggregate<T>) QueryUtils.createInstance(tClass); RunThread runThread = new RunThread(i, list.get(i), batchSize, noOfThread, ft); Future<Aggregate<T>> t = executor.submit(runThread); results.add(t); } catch (Exception ex) { logger.error(ex.getMessage(), ex); } } for (Future<Aggregate<T>> each : results) { try { aggregate.aggregate(each.get().get()); } catch (Exception ex) { logger.error(ex.getMessage(), ex); } } executor.shutdown(); return aggregate.get(); }
From source file:com.alibaba.wasp.fserver.SplitThread.java
/** @param server */ SplitThread(FServer server) {/*from ww w . j av a 2 s . c o m*/ super(); this.server = server; this.conf = server.getConfiguration(); this.entityGroupSplitLimit = conf.getInt("wasp.fserver.entityGroupSplitLimit", Integer.MAX_VALUE); int splitThreads = conf.getInt("wasp.fserver.thread.split", 1); final String n = Thread.currentThread().getName(); this.splits = (ThreadPoolExecutor) Executors.newFixedThreadPool(splitThreads, new ThreadFactory() { @Override public Thread newThread(Runnable r) { Thread t = new Thread(r); t.setName(n + "-splits-" + System.currentTimeMillis()); return t; } }); }
From source file:com.baifendian.swordfish.execserver.runner.adhoc.AdHocRunnerManager.java
public AdHocRunnerManager(Configuration conf) { adHocDao = DaoFactory.getDaoInstance(AdHocDao.class); int threads = conf.getInt(Constants.EXECUTOR_ADHOCRUNNER_THREADS, Constants.defaultAdhocExecutorNum); ThreadFactory flowThreadFactory = new ThreadFactoryBuilder().setNameFormat("Exec-Server-AdHocRunner") .build();/* www . ja v a 2 s.c o m*/ adHocExecutorService = Executors.newFixedThreadPool(threads, flowThreadFactory); }
From source file:com.cognifide.qa.bb.junit.concurrent.ConcurrentSuiteRunnerScheduler.java
/** * Constructs ConcurrentSuiteRunnerScheduler. * * @param clazz/*from w ww . java2 s .com*/ * @param properties * @param reportingHandler */ ConcurrentSuiteRunnerScheduler(Class<?> clazz, Properties properties, ReportingHandler reportingHandler, WebDriverRegistry webDriverRegistry) { this.properties = properties; this.reportingHandler = reportingHandler; this.webDriverRegistry = webDriverRegistry; executorService = Executors.newFixedThreadPool(determineNumberOfThreads(clazz), new NamedThreadFactory(clazz.getSimpleName())); completionService = new ExecutorCompletionService<>(executorService); }
From source file:com.vsct.dt.hesperides.indexation.ElasticSearchIndexationExecutor.java
public ElasticSearchIndexationExecutor(final ElasticSearchClient elasticSearchClient, final int nRetries, final int waitBeforeRetryMs) { this.nRetries = nRetries; this.waitBeforeRetryMs = waitBeforeRetryMs; this.elasticSearchClient = elasticSearchClient; ThreadFactory threadFactory = new ThreadFactoryBuilder().setDaemon(false) .setNameFormat("ElasticSearchIndexer-%d").build(); this.singleThreadPool = Executors.newFixedThreadPool(1, threadFactory); }