List of usage examples for java.util.concurrent Executors newFixedThreadPool
public static ExecutorService newFixedThreadPool(int nThreads)
From source file:com.linkedin.pinot.core.query.scheduler.QueryScheduler.java
public QueryScheduler(@Nullable QueryExecutor queryExecutor) { numQueryRunnerThreads = DEFAULT_QUERY_RUNNER_THREADS; numQueryWorkerThreads = DEFAULT_QUERY_WORKER_THREADS; this.queryExecutor = queryExecutor; queryRunners = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(numQueryRunnerThreads)); queryWorkers = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(numQueryWorkerThreads)); }
From source file:io.ucoin.ucoinj.elasticsearch.service.ExecutorServiceImpl.java
public ExecutorServiceImpl() { this.jobsById = Maps.newHashMap(); this.config = Configuration.instance(); this.progressionByJobIdCache = initJobByIdCache(config.getTaskExecutorQueueCapacity() * 2, config.getTaskExecutorTimeToIdle()); delegate = MoreExecutors/*from ww w . j a v a2s . c o m*/ .listeningDecorator(Executors.newFixedThreadPool(config.getTaskExecutorQueueCapacity())); }
From source file:com.google.api.ads.adwords.awreporting.server.kratu.KratuProcessor.java
public void processKratus(Long topAccountId, Set<Long> accountIdsSet, Date dateStart, Date dateEnd) throws InterruptedException { System.out.println("Processing Kratus for " + topAccountId); // We use a Latch so the main thread knows when all the worker threads are complete. final CountDownLatch latch = new CountDownLatch(1); Stopwatch stopwatch = Stopwatch.createStarted(); RunnableKratu runnableKratu = createRunnableKratu(topAccountId, accountIdsSet, storageHelper, dateStart, dateEnd);/*from w w w.j a v a2 s.c om*/ ExecutorService executorService = Executors.newFixedThreadPool(1); runnableKratu.setLatch(latch); executorService.execute(runnableKratu); latch.await(); stopwatch.stop(); }
From source file:com.wenyu.clustertools.Snapshot.java
@Override public void execute() { ExecutorService executor = Executors.newFixedThreadPool(parallel); Map<ClusterToolCmd.Node, Future<String>> futures = new HashMap<>(); for (ClusterToolCmd.Node node : nodes) { futures.put(node, executor.submit(new Executor(node))); }/*from ww w . j a v a2s.co m*/ for (Map.Entry<ClusterToolCmd.Node, Future<String>> future : futures.entrySet()) { try { System.out.println(future.getValue().get(Constants.MAX_PARALLEL_WAIT_IN_SEC, TimeUnit.SECONDS)); } catch (Exception ex) { System.out .println(String.format("%s failed with error: %s", future.getKey().server, ex.toString())); ex.printStackTrace(); } } }
From source file:com.norconex.committer.AbstractFileQueueCommitterTest.java
@Test public void testMultipleCommitThread() throws Exception { final AtomicInteger counter = new AtomicInteger(); final AbstractFileQueueCommitter committer = new AbstractFileQueueCommitter() { @Override/* w w w.j a va 2s . c o m*/ protected void commitAddition(IAddOperation operation) throws IOException { counter.incrementAndGet(); operation.delete(); } @Override protected void commitDeletion(IDeleteOperation operation) throws IOException { counter.incrementAndGet(); operation.delete(); } @Override protected void commitComplete() { } }; File queue = temp.newFolder(); committer.setQueueDir(queue.getPath()); // Use a bigger number to make sure the files are not // committed while they are added. committer.setQueueSize(1000); // Queue 50 files for additions for (int i = 0; i < 50; i++) { Properties metadata = new Properties(); committer.add(Integer.toString(i), IOUtils.toInputStream("hello world!"), metadata); } // Queue 50 files for deletions for (int i = 50; i < 100; i++) { Properties metadata = new Properties(); committer.remove(Integer.toString(i), metadata); } ExecutorService pool = Executors.newFixedThreadPool(10); for (int i = 0; i < 10; i++) { pool.submit(new Runnable() { @Override public void run() { try { committer.commit(); } catch (Exception e) { e.printStackTrace(); } } }); } pool.shutdown(); pool.awaitTermination(10, TimeUnit.SECONDS); // Each file should have been processed exactly once assertEquals(100, counter.intValue()); // All files should have been processed Collection<File> files = FileUtils.listFiles(queue, null, true); assertTrue(files.isEmpty()); }
From source file:edu.msu.cme.rdp.kmer.cli.KmerCoverage.java
/** * This program maps the kmers from reads to kmers on each contig, * writes the mean, median coverage of each contig to a file * writes the kmer abundance to a file// w w w . j av a 2s . c o m * @param args * @throws IOException */ public static void main(String[] args) throws IOException, InterruptedException { int kmerSize = 45; final int maxThreads; final int maxTasks = 1000; final PrintStream match_reads_out; try { CommandLine cmdLine = new PosixParser().parse(options, args); args = cmdLine.getArgs(); if (args.length < 5) { throw new Exception("Unexpected number of arguments"); } kmerSize = Integer.parseInt(args[0]); if (kmerSize > Kmer.max_nucl_kmer_size) { throw new Exception("kmerSize should be less than " + Kmer.max_nucl_kmer_size); } if (cmdLine.hasOption("match_reads_out")) { match_reads_out = new PrintStream(cmdLine.getOptionValue("match_reads_out")); } else { match_reads_out = null; } if (cmdLine.hasOption("threads")) { maxThreads = Integer.valueOf(cmdLine.getOptionValue("threads")); if (maxThreads >= Runtime.getRuntime().availableProcessors()) { System.err.println(" Runtime.getRuntime().availableProcessors() " + Runtime.getRuntime().availableProcessors()); } } else { maxThreads = 1; } final KmerCoverage kmerCoverage = new KmerCoverage(kmerSize, new SequenceReader(new File(args[1]))); final AtomicInteger outstandingTasks = new AtomicInteger(); ExecutorService service = Executors.newFixedThreadPool(maxThreads); Sequence seq; // parse one file at a time for (int index = 4; index < args.length; index++) { SequenceReader reader = new SequenceReader(new File(args[index])); while ((seq = reader.readNextSequence()) != null) { if (seq.getSeqString().length() < kmerSize) { continue; } final Sequence threadSeq = seq; Runnable r = new Runnable() { public void run() { try { kmerCoverage.processReads(threadSeq, match_reads_out); outstandingTasks.decrementAndGet(); } catch (Exception e) { e.printStackTrace(); } } }; outstandingTasks.incrementAndGet(); service.submit(r); while (outstandingTasks.get() >= maxTasks) ; } reader.close(); } service.shutdown(); service.awaitTermination(1, TimeUnit.DAYS); kmerCoverage.printCovereage(new FileOutputStream(new File(args[2])), new FileOutputStream(new File(args[3]))); if (match_reads_out != null) { match_reads_out.close(); } } catch (Exception e) { new HelpFormatter().printHelp( "KmerCoverage <kmerSize> <query_file> <coverage_out> <abundance_out> <reads_file> <reads_file>...\nmaximum kmerSize " + Kmer.max_nucl_kmer_size, options); e.printStackTrace(); System.exit(1); } }
From source file:com.legstar.host.server.PoolingTest.java
/** * Schedule some basic work./*from ww w . j a va2 s . c o m*/ * @throws Exception if failure */ public void testScheduleWork() throws Exception { ExecutorService executor = Executors.newFixedThreadPool(CLIENT_THREADS); WorkManager wm = new WorkManagerImpl(executor); EngineHandler engHandler = new EngineHandler(getPoolingEngineConfig()); engHandler.init(); LegStarAddress address = new LegStarAddress("TheMainframe"); address.setHostUserID(HOST_USERID); address.setHostPassword(HOST_PASSWORD); LegStarRequest request = new LegStarRequest("Request01", address, getLsfileaeRequestMessage()); Client client = new Client(engHandler.getEngine(), "Client01", request); wm.schedule(client, new ClientListener()); Thread.sleep(5000L); engHandler.stop(); executor.shutdownNow(); assertEquals(LsfileaeCases.getHostBytesHexReply100(), HostData.toHexString(request.getResponseMessage().getDataParts().get(0).getContent())); }
From source file:com.appdynamics.monitors.hadoop.communicator.AmbariCommunicator.java
/** * Constructs a new AmbariCommunicator. Metrics can be collected by calling {@link #populate(java.util.Map)} * Only metrics that match the conditions in <code>xmlParser</code> are collected. * * @param host//from w ww .j av a 2 s . c o m * @param port * @param user * @param password * @param logger * @param xmlParser XML parser for metric filtering */ public AmbariCommunicator(String host, String port, String user, String password, Logger logger, Parser xmlParser) { this.host = host; this.port = port; this.user = user; this.password = password; this.logger = logger; this.xmlParser = xmlParser; executor = Executors.newFixedThreadPool(xmlParser.getThreadLimit()); }
From source file:org.ops4j.orient.spring.tx.document.DocumentDatabaseTransactionTest.java
@Test public void commitMultiThreaded() throws InterruptedException { ExecutorService executorService = Executors.newFixedThreadPool(5); for (int i = 0; i < 5; i++) { executorService.submit(new CommitTask()); }/* w w w . j av a2 s . c o m*/ executorService.shutdown(); executorService.awaitTermination(1000, TimeUnit.SECONDS); }
From source file:eu.serco.dhus.plugin.sral.SralPlugin.java
public SralPlugin() { executor = Executors.newFixedThreadPool(MAX_THREADS_NUMBER); map = new HashMap<String, String>(); map.put("SR_1_CAL___", "SR_1_CAL"); map.put("SR_1_SRA___", "SR_1_MEAS"); map.put("SR_2_WAT___", "SR_2"); map.put("SR_2_LAN___", "SR_2"); try {//from w ww .j a va2 s.c o m loadTaskTables(); loadSelectionRulesProperties(); externalDHuSUrl = ConfigurationManager.getExternalDHuSHost(); hashedString = ConfigurationManager.getHashedConnectionString(); } catch (ParserConfigurationException pce) { pce.printStackTrace(); } catch (SAXException saxe) { saxe.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }