Java 8 CompletionService - 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 CompletionService class.

This code example shows how to use the following methods:take
		checkStreamState(); 
		dispatchWrite(m_CurrentBufferedBytes);
	} 
	private void waitForTaskToComplete() throws IOException {
		try { 
			Future<Void> future = m_CompletionService.take();
			future.get();
		} catch (Exception exception) {
			IOException ioException = new IOException();
			ioException.initCause(exception);
			throw ioException;
		} 
		m_OutstandingRequests--;
	} 
	@Override 
	public void write(byte buffer[]) throws IOException {
		write(buffer, 0, buffer.length);
	} 
	public void write(byte buffer[], int bufferOffset, int length)
			throws IOException {
4
CodeRank
This code example shows how to use the following methods:submit
   *          the callable 
   */ 
  public void submitTask(Callable<Object> task) {
    if (!cancel) {
      taskcount++;
      service.submit(task);
    } 
  } 
 
  /** 
   * submits a new runnable to thread pool. 
   *  
   * @param task 
   *          the runnable 
   */ 
  public void submitTask(Runnable task) {
    if (!cancel) {
      taskcount++;
      service.submit(task, null);
    } 
4
CodeRank
This code example shows how to use the following methods:submit
     * Submits a Callable for execution. 
     * 
     * @param runnable the callable to run. 
     */ 
    public void execute(Callable<T> runnable) {
        mFutureSet.add(mCompletionService.submit(runnable));
    } 
 
    /** 
     * Waits for all tasks to be executed. If a tasks throws an exception, it will be thrown from 
     * this method inside the ExecutionException, preventing access to the result of the other 
     * threads. 
     * 
     * If you want to get the results of all tasks (result and/or exception), use 
     * {@link #waitForAllTasks()} 
     * 
     * @param cancelRemaining if true, and a task fails, cancel all remaining tasks. 
     * 
     * @return a list of all the return values from the tasks. 
     * 
4
CodeRank
This code example shows how to use the following methods:submit
	 * through a CompletionService 
	 */ 
	@Override 
	public void run() { 
			ReportGenerator reportGenerator=new ReportGenerator(name, "Report");
			service.submit(reportGenerator);
	} 
 
} 
4
CodeRank
This code example shows how to use the following methods:poll, submit
        } 
        return profileRegistry.hasProfile(version, profile);
    } 
 
    public static Object getMBean(final Container container, final ObjectName mbeanName, final Class clazz, final long timeout) throws Exception {
        CompletionService<Object> completionService = new ExecutorCompletionService<Object>(EXECUTOR);
        completionService.submit(new Callable<Object>() {
            @Override 
            public Object call() throws Exception { 
                long time = 0; 
                while (time <= timeout) { 
                    try { 
                        JMXServiceURL url = new JMXServiceURL(container.getJmxUrl()); 
                        Map env = new HashMap(); 
                        String[] creds = {"admin", "admin"}; 
                        env.put(JMXConnector.CREDENTIALS, creds); 
                        JMXConnector jmxc = JMXConnectorFactory.connect(url, env); 
                        MBeanServerConnection mbsc = jmxc.getMBeanServerConnection(); 
                        mbsc.getObjectInstance(mbeanName); 
                        return JMX.newMBeanProxy(mbsc, mbeanName, clazz, true); 

4
CodeRank
This code example shows how to use the following methods:poll
 
	/* (non-Javadoc) 
	 * @see java.util.concurrent.CompletionService#poll() 
	 */ 
	public Future<MergeResult> poll() { 
		return completionService.poll(); 
	} 
 
	/* (non-Javadoc) 
	 * @see java.util.concurrent.CompletionService#poll(long, java.util.concurrent.TimeUnit) 
	 */ 
	public Future<MergeResult> poll(long timeout, TimeUnit unit) 
			throws InterruptedException { 
		return completionService.poll(timeout, unit); 
	} 
 
	/* (non-Javadoc) 
	 * @see java.util.concurrent.CompletionService#take() 
	 */ 
	public Future<MergeResult> take() throws InterruptedException { 
4
CodeRank
This code example shows how to use the following methods:submit
	 
	ExecutorService executorService;
	CompletionService<Integer> completionService;
	 
	public void addTask(Callable<Integer> task) {
		completionService.submit(task);
	} 
	 
	@Override 
	protected void finalize() throws Throwable { 
		executorService.shutdown();
		super.finalize(); 
	} 
} 
4
CodeRank
This code example shows how to use the following methods:submit
 
       @param callable ÃͤòÊÖ¤¹¼Â¹ÔÍÑ¥¿¥¹¥¯ 
    */ 
    public void submit(final Callable<T> callable) {
	++taskCount;
	service.submit(callable);
    } 
 
    /** 
       ¥µ¡¼¥Ó¥¹¤«¤é·ë²Ì¤ò¼èÆÀ¤·¡¢¥ê¥¹¥Ê¤ËÄÌÃΤ·¤Þ¤¹¡£¤¹¤Ù¤Æ¤Î¥¿¥¹¥¯¤Î 
       ·ë²Ì¤òÄÌÃΤǤ­¤ë¤Þ¤Ç¥Ö¥í¥Ã¥¯¤·¤Þ¤¹¡£ 
 
       @param listener ¥ê¥¹¥Ê 
       @throws ExecutionException ¥ï¡¼¥«¥¹¥ì¥Ã¥É¤¬Îã³°¤ò¥¹¥í¡¼ 
    */ 
    public void deliver(final DeliveryListener<T> listener)
	throws ExecutionException { 
 	try { 
	    while (taskCount > 0) {
		Future<T> future = service.take();
4
CodeRank
This code example shows how to use the following methods:submit
    } 
 
    @Override 
    public void run() { 
        ReportGenerator reportGenerator = new ReportGenerator(name, "Report");
        service.submit(reportGenerator);
    } 
} 
4
CodeRank
This code example shows how to use the following methods:poll
 
	/* (non-Javadoc) 
	 * @see java.util.concurrent.CompletionService#poll() 
	 */ 
	public Future<GenerateResult> poll() { 
		return completionService.poll(); 
	} 
 
	/* (non-Javadoc) 
	 * @see java.util.concurrent.CompletionService#poll(long, java.util.concurrent.TimeUnit) 
	 */ 
	public Future<GenerateResult> poll(long timeout, TimeUnit unit) 
			throws InterruptedException { 
		return completionService.poll(timeout, unit); 
	} 
 
	/* (non-Javadoc) 
	 * @see java.util.concurrent.CompletionService#take() 
	 */ 
	public Future<GenerateResult> take() throws InterruptedException { 
4
CodeRank
See Code Examples for Java 8 CompletionService Methods: