List of usage examples for java.util.concurrent Future get
V get() throws InterruptedException, ExecutionException;
From source file:main.ScorePipeline.java
/** * This method calculates similarities bin-based between yeast_human spectra * on the first data set against all yeast spectra on the second data set * * @param min_mz/*from www . ja v a 2s . c om*/ * @param max_mz * @param topN * @param percentage * @param yeast_and_human_file * @param is_precursor_peak_removal * @param fragment_tolerance * @param noiseFiltering * @param transformation * @param intensities_sum_or_mean_or_median * @param yeast_spectra * @param bw * @param charge * @param charge_situation * @throws IllegalArgumentException * @throws ClassNotFoundException * @throws IOException * @throws MzMLUnmarshallerException * @throws NumberFormatException * @throws ExecutionException * @throws InterruptedException */ private static void calculate_BinBasedScoresObsolete_AllTogether(ArrayList<BinMSnSpectrum> yeast_spectra, ArrayList<BinMSnSpectrum> yeast_human_spectra, BufferedWriter bw, int charge, double precursorTol, double fragTol) throws IllegalArgumentException, ClassNotFoundException, IOException, MzMLUnmarshallerException, NumberFormatException, InterruptedException { ExecutorService excService = Executors .newFixedThreadPool(ConfigHolder.getInstance().getInt("thread.numbers")); List<Future<SimilarityResult>> futureList = new ArrayList<>(); for (BinMSnSpectrum binYeastHumanSp : yeast_human_spectra) { int tmpMSCharge = binYeastHumanSp.getSpectrum().getPrecursor().getPossibleCharges().get(0).value; if (charge == 0 || tmpMSCharge == charge) { if (!binYeastHumanSp.getSpectrum().getPeakList().isEmpty() && !yeast_spectra.isEmpty()) { Calculate_Similarity similarity = new Calculate_Similarity(binYeastHumanSp, yeast_spectra, fragTol, precursorTol); Future future = excService.submit(similarity); futureList.add(future); } } } for (Future<SimilarityResult> future : futureList) { try { SimilarityResult get = future.get(); String tmp_charge = get.getSpectrumChargeAsString(), spectrum = get.getSpectrumName(); double tmpPrecMZ = get.getSpectrumPrecursorMZ(); double dot_product = get.getScores().get(SimilarityMethods.NORMALIZED_DOT_PRODUCT_STANDARD), dot_product_skolow = get.getScores().get(SimilarityMethods.NORMALIZED_DOT_PRODUCT_SOKOLOW), pearson = get.getScores().get(SimilarityMethods.PEARSONS_CORRELATION), spearman = get.getScores().get(SimilarityMethods.SPEARMANS_CORRELATION); if (dot_product == Double.MIN_VALUE) { LOGGER.info("The similarity for the spectrum " + spectrum + " is too small to keep the record, therefore score is not computed."); // Means that score has not been calculated! // bw.write(tmp_Name + "\t" + tmp_charge + "\t" + tmpPrecMZ + "\t"); // bw.write("NA" + "\t" + "NA" + "\t" + "NA" + "\t" + "NA"); } else { bw.write(spectrum + "\t" + tmp_charge + "\t" + tmpPrecMZ + "\t" + get.getSpectrumToCompare() + "\t"); bw.write(dot_product + "\t" + dot_product_skolow + "\t" + pearson + "\t" + spearman + "\n"); } } catch (InterruptedException | ExecutionException e) { LOGGER.error(e); } } }
From source file:com.sillelien.dollar.api.types.DollarFactory.java
/** * From future.// w w w . j ava 2s.c om * * @param future the future * @return the var */ @NotNull public static var fromFuture(@NotNull Future<var> future) { return wrap((var) java.lang.reflect.Proxy.newProxyInstance(DollarStatic.class.getClassLoader(), new Class<?>[] { var.class }, new DollarLambda(i -> future.get(), false))); }
From source file:Main.java
public void processUsers(int numOfWorkerThreads) { ExecutorService threadPool = Executors.newFixedThreadPool(numOfWorkerThreads); int chunk = itemsToBeProcessed.length / numOfWorkerThreads; int start = 0; List<Future> tasks = new ArrayList<Future>(); for (int i = 0; i < numOfWorkerThreads; i++) { tasks.add(threadPool.submit(new WorkerThread(start, start + chunk))); start = start + chunk;//from ww w .j av a 2 s. co m } // join all worker threads to main thread for (Future f : tasks) { try { f.get(); } catch (Exception e) { e.printStackTrace(); } } threadPool.shutdown(); while (!threadPool.isTerminated()) { } }
From source file:eu.tripledframework.demo.presentation.HelloController.java
@RequestMapping(value = "/hello/{name}", method = RequestMethod.GET) public HelloResponse sayHi(@PathVariable String name) throws ExecutionException, InterruptedException { Future<HelloResponse> future = commandDispatcher.dispatch(new HelloCommand(name)); return future.get(); }
From source file:com.kurento.test.player.ParallelPlayerIT.java
private void testParallelPlay(String url, int statusCode, String contentType, boolean interrupt, String[] expectedHandlerFlow) throws ClientProtocolException, IOException, InterruptedException, ExecutionException { ExecutorService execute = Executors.newFixedThreadPool(nThreads); Collection<Future<?>> futures = new LinkedList<Future<?>>(); // Perform nThreads calls for (int i = 0; i < nThreads; i++) { futures.add(execute.submit(//from w ww. j a v a 2s. co m new PlayerTst(url, getServerPort(), statusCode, contentType, interrupt, expectedHandlerFlow))); } // Wait for all threads to be terminated for (Future<?> future : futures) { future.get(); } }
From source file:hivemall.smile.utils.SmileTaskExecutor.java
public <T> List<T> run(Collection<? extends Callable<T>> tasks) throws Exception { final List<T> results = new ArrayList<T>(tasks.size()); if (exec == null) { for (Callable<T> task : tasks) { results.add(task.call());//from w ww. ja va 2 s . c o m } } else { final List<Future<T>> futures = exec.invokeAll(tasks); for (Future<T> future : futures) { results.add(future.get()); } } return results; }
From source file:com.stb.async.ParallelExecutionProcess.java
/** * * @param processList/*from www. ja v a 2 s. co m*/ */ public void initiateDecode(List processList) { Date startTime = new java.util.Date(); System.out.println("Start Work" + startTime); ExecutorService es = Executors.newFixedThreadPool(10); Collections.sort(processList, new ProcessCompare()); List<Future> futures = new ArrayList<>(); for (Iterator it = processList.iterator(); it.hasNext();) { Process e = (Process) it.next(); workerId = processList.indexOf(e); System.out.println("* Start Decode process " + processList.indexOf(e)); futures.add(es.submit(() -> { new DecodedSTBProcesses((Process) processList.get(ParallelExecutionProcess.workerId)).doWork(); return null; })); } es.shutdown(); System.out.println( "... The Process is under execution! Using CPU core which are available, wait while work is being done...."); int ctr = 0; for (Future future : futures) { try { future.get(); // blocking call, explicitly waiting for the response from a specific task, not necessarily the first task that is completed System.out.println("** Response of process " + ++ctr + " is in."); } catch (InterruptedException | ExecutionException e) { } } Date endTime = new java.util.Date(); System.out.println("End work at " + endTime); System.out.println("Total decoding took " + new Double(0.001 * (endTime.getTime() - startTime.getTime())) + " seconds"); System.exit(0); }
From source file:com.unitt.commons.authorization.hazelcast.call.HasPermissionCallback.java
public void done(Future<Boolean> aResult) { try {//from w w w . j a va2s . com current++; if (aResult.get()) { hasResult = true; result = true; synchronized (this) { notifyAll(); } } } catch (Exception e) { log.error("Could not acquire result.", e); } if (current == total) { hasResult = true; synchronized (this) { notifyAll(); } } }
From source file:com.github.tomakehurst.wiremock.ResponseDelaySynchronousFailureAcceptanceTest.java
@Test public void requestIsFailedWhenMultipleRequestsHitSynchronousServer() throws Exception { stubFor(get(urlEqualTo("/delayed")) .willReturn(aResponse().withStatus(200).withFixedDelay(SHORTER_THAN_SOCKET_TIMEOUT))); List<Future<HttpResponse>> responses = httpClientExecutor.invokeAll(getHttpRequestCallables(10)); try {// w w w . j av a 2 s. c o m for (Future<HttpResponse> response : responses) { assertThat(response.get().getStatusLine().getStatusCode(), is(200)); } fail("A timeout exception expected reading multiple responses from synchronous WireMock server"); } catch (ExecutionException e) { assertThat(e.getCause(), instanceOf(SocketTimeoutException.class)); assertThat(e.getCause().getMessage(), is("Read timed out")); } }
From source file:org.dasein.cloud.utils.requester.DaseinParallelRequestExecutor.java
public List<T> execute() throws DaseinRequestException { final HttpClientBuilder clientBuilder = setProxyIfRequired(httpClientBuilder); final CloseableHttpClient httpClient = clientBuilder.build(); List<T> results = new ArrayList<T>(); List<Callable<T>> tasks = new ArrayList<Callable<T>>(); for (final HttpUriRequest httpUriRequest : httpUriRequests) { tasks.add(new Callable<T>() { @Override/*from w ww.ja v a 2s. c o m*/ public T call() throws Exception { return execute(httpClient, httpUriRequest); } }); } try { try { ExecutorService executorService = Executors.newFixedThreadPool(httpUriRequests.size()); List<Future<T>> futures = executorService.invokeAll(tasks); for (Future<T> future : futures) { T result = future.get(); results.add(result); } return results; } finally { httpClient.close(); } } catch (Exception e) { throw new DaseinRequestException(e.getMessage(), e); } }