Java 8 ExecutorCompletionService - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 ExecutorCompletionService class.

This code example shows how to use the following methods:
 */ 
public class Main { 
 
    public static void main(String[] args) {
        ExecutorService executor = Executors.newCachedThreadPool();
        CompletionService<String> service = new ExecutorCompletionService<>(executor);
        ReportRequest faceRequest = new ReportRequest("Face", service);
        ReportRequest onlineRequest = new ReportRequest("Online", service);
        Thread faceThread = new Thread(faceRequest);
        Thread onlineThread = new Thread(onlineRequest);
 
        ReportProcessor processor = new ReportProcessor(service);
        Thread senderThread = new Thread(processor);
 
        System.out.println("Main: starting the Threads");
 
        faceThread.start();
        onlineThread.start();
        senderThread.start();
        try { 
5
CodeRank
This code example shows how to use the following methods:
	 * @param args 
	 */ 
	public static void main(String[] args) {
		// Create the executor and thee CompletionService using that executor 
		ExecutorService executor=(ExecutorService)Executors.newCachedThreadPool();
		CompletionService<String> service=new ExecutorCompletionService<>(executor);
 
		// Crete two ReportRequest objects and two Threads to execute them 
		ReportRequest faceRequest=new ReportRequest("Face", service);
		ReportRequest onlineRequest=new ReportRequest("Online", service);
		Thread faceThread=new Thread(faceRequest);
		Thread onlineThread=new Thread(onlineRequest);
		 
		// Create a ReportSender object and a Thread to execute  it 
		ReportProcessor processor=new ReportProcessor(service);
		Thread senderThread=new Thread(processor);
		 
		// Start the Threads 
		System.out.printf("Main: Starting the Threads\n");
		faceThread.start();
5
CodeRank
This code example shows how to use the following methods:
This code example shows how to use the following methods:
 
    private volatile ExecutorCompletionService completionService = null;
    private volatile List<Future>              futures           = null;
 
    public void start() { 
        completionService = new ExecutorCompletionService(executor);
        futures = Collections.synchronizedList(new ArrayList<Future>());
    } 
 
    public void submit(Callable<Exception> task) {
        Future future = completionService.submit(task);
        futures.add(future);
        check(future);// 立即check下,fast-fail
    } 
 
    public void submit(Runnable task) {
        Future future = completionService.submit(task, null);
        futures.add(future);
        check(future);// 立即check下,fast-fail
    } 
5
CodeRank
This code example shows how to use the following methods:
		  { 
				 return new ExecutorCompletionService<ShardResponse>(EXECUTE[i]); 
		  } 
		   
		   
		return new ExecutorCompletionService<ShardResponse>(commExecutor); 
 
	  } 
	   
} 
 
// 
//public class MergerServerThreads { 
//	 
//	 
//	/** 
//	 *  
//	 *  
//	  new ThreadPoolExecutor( 
//	          2, 
5
CodeRank
This code example shows how to use the following methods:
        this.size = 1;
      } 
      executor = Executors.newFixedThreadPool(size);
    } 
    if(completion==null) {
      completion = new ExecutorCompletionService(executor);
    } 
    try { 
      for(int i=0;i<fileList.length;i++) {
        String filename = fileList[i].getPath().toUri().toString();
        log.info("Processing: "+filename);
        completion.submit(new MetricDataLoader(conf, fs, filename));      
      } 
      for(int i=0;i<fileList.length;i++) {
        completion.take().get();
      } 
    } catch(Exception e) {
      log.error(ExceptionUtil.getStackTrace(e));
      throw new IOException();
    } finally { 
4
CodeRank
This code example shows how to use the following methods:
		super(); 
		// Create the ExecutorService implementations and construct 
		// the CompletionService implementations 
		final ExecutorService generatorExecutor = Executors.newFixedThreadPool(generatorTaskThreads);
		final ExecutorService templateExecutor = Executors.newFixedThreadPool(templateTaskThreads);
		this.generatorTaskCompletionService = new GeneratorTaskCompletionService(new ExecutorCompletionService<GenerateResult>(generatorExecutor));	
		this.templateTaskCompletionService = new TemplateTaskCompletionService(new ExecutorCompletionService<MergeResult>(templateExecutor));
	} 
 
	public void addGeneratorTask(Generator generator, Model model, Template template) throws InterruptedException, ExecutionException {
		 
		// Create the GeneratorTask task and submit 
		GeneratorTask generatorTask = new GeneratorTask(generator, model, template, templateTaskCompletionService);
		generatorTaskCompletionService.submit(generatorTask);
	} 
		 
		 
	public void getResults(Collection<GenerateResult> generateResults, Collection<MergeResult> mergeResults) throws InterruptedException, ExecutionException {
		// As each GeneratorTask completes, get the GenerateResult 
		for (int t = 0, n = generatorTaskCompletionService.getTaskCount(); t < n; t ++) {
4
CodeRank
This code example shows how to use the following methods:
     * Creates an CLTaskCompletionService using the supplied executor for base 
     * task execution and a LinkedBlockingQueue with the capacity of {@link Integer#MAX_VALUE} 
     * as a completion queue. 
     */ 
    public CLTaskCompletionService(CLExecutorService executor) {
        this.service = new ExecutorCompletionService<R>(executor.getExcecutor());
        this.executor = executor;
    } 
 
    /** 
     * Creates an CLTaskCompletionService using the supplied executor for base 
     * task execution the supplied queue as its completion queue. 
     */ 
    public CLTaskCompletionService(CLExecutorService pool, BlockingQueue<Future<R>> queue) {
        this.service = new ExecutorCompletionService<R>(pool.getExcecutor(), queue);
        this.executor = pool;
    } 
 
    /** 
     * Submits a CLTask for execution and returns a Future representing the pending 
3
CodeRank
This code example shows how to use the following methods:
        this.size = 1;
      } 
      executor = Executors.newFixedThreadPool(size);
    } 
    if(completion==null) {
      completion = new ExecutorCompletionService(executor);
    } 
    try { 
      for(int i=0;i<fileList.length;i++) {
        String filename = fileList[i].getPath().toUri().toString();
        log.info("Processing: "+filename);
        completion.submit(new MetricDataLoader(conf, fs, filename));      
      } 
      for(int i=0;i<fileList.length;i++) {
        completion.take().get();
      } 
    } catch(Exception e) {
      log.error(ExceptionUtil.getStackTrace(e));
      throw new IOException();
    } 
4
CodeRank
This code example shows how to use the following methods:
	/** 
	 * 新建一个CompletionService,调用其submit方法可以异步执行多个任务,最后调用take方法按照完成的顺序获得其结果。,若未完成,则会阻塞 
	 * @return CompletionService 
	 */ 
	public static<T> CompletionService<T> newCompletionService(){
		return new ExecutorCompletionService<T>(executor);
	} 
	 
	/** 
	 * 新建一个CompletionService,调用其submit方法可以异步执行多个任务,最后调用take方法按照完成的顺序获得其结果。,若未完成,则会阻塞 
	 * @return CompletionService 
	 */ 
	public static<T> CompletionService<T> newCompletionService(ExecutorService executor){
		return new ExecutorCompletionService<T>(executor);
	} 
} 
3
CodeRank
See Code Examples for Java 8 ExecutorCompletionService Methods: