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

This code example shows how to use the following methods:call
            this.callable = callable;
        } 
 
        @Override 
        public T call() throws Exception { 
            return callable.call();
        } 
    } 
} 
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:call
      // hook into lifecycle 
      DistributedTaskLifecycleService taskLifecycleService = DistributedTaskLifecycleService.getInstance();
      Callable<V> callable = getCallable();
      V result = null;
      try { 
         taskLifecycleService.onPreExecute(callable, cache);
         if (callable instanceof DistributedCallable<?, ?, ?>) {
            DistributedCallable<Object, Object, Object> dc = (DistributedCallable<Object, Object, Object>) callable;
            dc.setEnvironment(cache, keys); 
         } 
         result = callable.call();
      } finally { 
         taskLifecycleService.onPostExecute(callable);
      } 
      return result;
   } 
 
   public Callable<V> getCallable() {
      return callable;
   } 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:call
            this.callable = callable;
        } 
 
        @Override 
        public T call() throws Exception {
            return callable.call();
        } 
    } 
} 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:call
  @Override 
  public Void call() throws Exception {
    if (runnable != null) {
      runnable.run();
    } else { 
      callable.call();
    } 
    return null; 
  } 
 
  /** 
   * Invokes the wrapped callable/runnable as a runnable. 
   * 
   * @throws RuntimeException thrown by the wrapped callable/runnable invocation. 
   */ 
  @Override 
  public void run() { 
    if (runnable != null) {
      runnable.run();
    } else { 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:toString
			return super.submit(ManagedTaskBuilder.buildManagedTask(task, task.toString()));
		} 
 
		@Override 
		public <T> Future<T> submit(Callable<T> task) {
			return super.submit(ManagedTaskBuilder.buildManagedTask(task, task.toString()));
		} 
 
		@Override 
		public ListenableFuture<?> submitListenable(Runnable task) {
			return super.submitListenable(ManagedTaskBuilder.buildManagedTask(task, task.toString()));
		} 
 
		@Override 
		public <T> ListenableFuture<T> submitListenable(Callable<T> task) {
			return super.submitListenable(ManagedTaskBuilder.buildManagedTask(task, task.toString()));
		} 
	} 
 
 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getClass
   @Override 
   @SuppressWarnings({ "unchecked" }) 
   public <T, K, V> void onPreExecute(Callable<T> task, Cache<K, V> inputCache) {
      BeanManager bm = BeanManagerProvider.getInstance().getBeanManager();
      ContextInputCache.set(inputCache); 
      Class<Callable<T>> clazz = (Class<Callable<T>>) task.getClass();
      AnnotatedType<Callable<T>> type = bm.createAnnotatedType(clazz);
      InjectionTarget<Callable<T>> it = bm.createInjectionTarget(type);
      CreationalContext<Callable<T>> ctx = bm.createCreationalContext(null);
      it.inject(task, ctx);
      it.postConstruct(task);    
   } 
 
   @Override 
   @SuppressWarnings({ "unchecked" }) 
   public <T> void onPostExecute(Callable<T> task) {
      try { 
         BeanManager bm = BeanManagerProvider.getInstance().getBeanManager();
         Class<Callable<T>> clazz = (Class<Callable<T>>) task.getClass();
         AnnotatedType<Callable<T>> type = bm.createAnnotatedType(clazz);
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:call
	public synchronized <T> T getResource(final String iName, final Callable<T> iCallback) {
		T value = (T) sharedResources.get(iName);
		if (value == null) {
			// CREATE IT 
			try { 
				value = iCallback.call();
			} catch (Exception e) {
				throw new OException("Error on creation of shared resource", e);
			} 
 
			if (value instanceof OSharedResource)
				((OSharedResource) value).acquireExclusiveLock();
 
			sharedResources.put(iName, value);
		} 
 
		return value;
	} 
} 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:call
	 * the {@link StepContribution} and the attributes. 
	 * @see Tasklet#execute(StepContribution, ChunkContext) 
	 */ 
	@Override 
	public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { 
		return callable.call(); 
	} 
 
} 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:call
    public void execute() throws BuildException { 
        if (null == getCallable()) { 
            throw new BuildException("CallableWrapperTask requires a Callable object"); 
        } 
        try { 
            resultObject = getCallable().call();
        } catch (Exception e) {
            throw new BuildException(e);
        } 
    } 
 
    public Callable getCallable() {
        return callable;
    } 
 
    public void setCallable(final Callable callable) {
        this.callable = callable;
    } 
 
    public Object getResultObject() {
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:call
        } 
    } 
 
    public <T> T callAs(final Authentication auth, final Callable<T> task) throws Exception {
        checkNotNull(auth);
        checkNotNull(task);
        final SecurityContext ctx = SecurityContextHolder.getContext();
        final Authentication current = ctx.getAuthentication();
        ctx.setAuthentication(auth);
        try { 
            return task.call();
        } 
        finally { 
            ctx.setAuthentication(current);
        } 
    } 
 
    public <T> T callAs2(final Authentication auth, final Callable<T> task) {
        try { 
            return callAs(auth, task);
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
See Code Examples for Java 8 Callable Methods: