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

This code example shows how to use the following methods:get
		assertEquals(1, getCorePoolSize(executor));
		assertEquals(Integer.MAX_VALUE, getMaxPoolSize(executor));
		assertEquals(Integer.MAX_VALUE, getQueueCapacity(executor));
		assertEquals(60, getKeepAliveSeconds(executor));
		assertEquals(false, getAllowCoreThreadTimeOut(executor));
		FutureTask<String> task = new FutureTask<String>(new Callable<String>() {
			@Override 
			public String call() throws Exception {
				return "foo"; 
			} 
		}); 
		((ThreadPoolTaskExecutor)executor).execute(task);
		assertEquals("foo", task.get());
	} 
 
	@Test
	public void singleSize() { 
		Object executor = this.context.getBean("singleSize");
		assertEquals(42, getCorePoolSize(executor));
		assertEquals(42, getMaxPoolSize(executor));
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
  protected WebDriverHandler(Session session) {
    this.session = session;
  } 
 
  public final ResultType handle() throws Exception { 
    FutureTask<ResultType> future = new FutureTask<ResultType>(this);
    try { 
      return getSession().execute(future);
    } catch (ExecutionException e) {
      Throwable cause = e.getCause();
      if (cause instanceof Exception)
        throw (Exception) cause;
      throw e;
    } 
  } 
 
  public SessionId getSessionId() { 
    return session.getSessionId();
  } 
 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:get
    final Thread retrieverThread;
 
    if (robot != null) {
      return robot;
    } 
    robotRetriever = new FutureTask<Robot>(new Retriever());
    log.info("Creating Robot");
    retrieverThread = new Thread(robotRetriever, "robotRetriever");  // Thread safety reviewed
    retrieverThread.start();
    robot = robotRetriever.get(10, TimeUnit.SECONDS);
 
    return robot;
  } 
 
} 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:post, get
	 
	public static <T> T callInMainThread(Callable<T> call) throws Exception {
		if (isMainThread()) 
			return call.call();
		else { 
			FutureTask<T> task = new FutureTask<T>(call);
			getHandler().post(task);
			return task.get();
		} 
	} 
} 
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
		try { 
			if (this.concurrentExecutor instanceof ExecutorService) {
				return ((ExecutorService) this.concurrentExecutor).submit(task);
			} 
			else { 
				FutureTask<T> future = new FutureTask<T>(task);
				this.concurrentExecutor.execute(future);
				return future;
			} 
		} 
		catch (RejectedExecutionException ex) {
			throw new TaskRejectedException(
					"Executor [" + this.concurrentExecutor + "] did not accept task: " + task, ex);
		} 
	} 
 
	@Override 
	public ListenableFuture<?> submitListenable(Runnable task) {
		try { 
			ListenableFutureTask<Object> future = new ListenableFutureTask<Object>(task, null);
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:run
        this.finishImmediately = finishImmediately;
    } 
 
    public Future<ProjectSegment> submit( Callable<ProjectSegment> task )
    { 
        FutureTask<ProjectSegment> projectBuildFutureTask = new FutureTask<ProjectSegment>( task );
        projectBuildFutureTasks.add( projectBuildFutureTask );
        if ( finishImmediately )
        { 
            projectBuildFutureTask.run();
        } 
        return projectBuildFutureTask;
    } 
 
    public Future<ProjectSegment> submit( Runnable task, ProjectSegment result )
    { 
        FutureTask<ProjectSegment> projectBuildFutureTask = new FutureTask<ProjectSegment>( task, result );
        projectBuildFutureTasks.add( projectBuildFutureTask );
        if ( finishImmediately )
        { 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
		return future;
	} 
 
	@Override 
	public <T> Future<T> submit(Callable<T> task) {
		FutureTask<T> future = new FutureTask<T>(task);
		execute(future);
		return future;
	} 
 
	@Override 
	public ListenableFuture<?> submitListenable(Runnable task) {
		ListenableFutureTask<Object> future = new ListenableFutureTask<Object>(task, null);
		execute(future);
		return future;
	} 
 
	@Override 
	public <T> ListenableFuture<T> submitListenable(Callable<T> task) {
		ListenableFutureTask<T> future = new ListenableFutureTask<T>(task);
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:post, get, run
     * @param c The Callable to run 
     * @return The result of the callable 
     * @throws ExecutionException c's exception 
     */ 
    public static <T> T runOnUiThreadBlocking(Callable<T> c) throws ExecutionException {
        FutureTask<T> task = new FutureTask<T>(c);
        runOnUiThread(task);
        try { 
            return task.get();
        } catch (InterruptedException e) {
            throw new RuntimeException("Interrupted waiting for callable", e);
        } 
    } 
 
    /** 
     * Run the supplied FutureTask on the main thread. The method will block only if the current 
     * thread is the main thread. 
     * 
     * @param task The FutureTask to run 
     * @return The queried task (to aid inline construction) 

6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:get
            @Override 
            public MediaPlayer call() throws Exception {
                return new MediaPlayer();
            } 
        }; 
        FutureTask<MediaPlayer> future = new FutureTask<MediaPlayer>(callable);
        getInstrumentation().runOnMainSync(future);
        return DynamicProxy.dynamicProxy(MediaPlayerProxy.class, future.get(1, TimeUnit.SECONDS));
    } 
} 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:get, run
			Callable<Map<String, Field>> callable = new Callable<Map<String, Field>>() {
				@Override public Map<String, Field> call() throws Exception {
					return collectFieldsFor(classToFindFieldsFor);
				} 
			}; 
			FutureTask<Map<String, Field>> newFutureTask = new FutureTask<Map<String, Field>>(callable);
			futureTask = CACHE.putIfAbsent(classToFindFieldsFor, newFutureTask);
			if (futureTask == null) {
				futureTask = newFutureTask;
				newFutureTask.run();
			} 
		} 
		try { 
			return futureTask.get();
		} catch (CancellationException e) {
			CACHE.remove(classToFindFieldsFor, futureTask);
		} catch (InterruptedException e) {
			throw new RuntimeException(e);
		} catch (ExecutionException e) {
			throw new RuntimeException(e);
		} 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
See Code Examples for Java 8 FutureTask Methods: