Java Thread Callable getFuture(ExecutorService executorService, Callable callable)

Here you can find the source of getFuture(ExecutorService executorService, Callable callable)

Description

Get a future from a given callable.

License

Apache License

Parameter

Parameter Description
executorService ExecutorService to use to get the Future.
callable the callable to run in the new Future.
RETVAL the return type of the callable and Future.

Return

a new Future representing asynchronous execution of the given callable.

Declaration

public static <RETVAL> Future<RETVAL> getFuture(ExecutorService executorService, Callable<RETVAL> callable) 

Method Source Code

//package com.java2s;
/**/* w  w  w  .  j  a v  a2 s . c o m*/
 * (c) Copyright 2013 WibiData, Inc.
 *
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.util.concurrent.Callable;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;

public class Main {
    /**
     * Get a future from a given callable.  This method uses the singleton FreshenerThreadPool to run
     * threads responsible for carrying out the operation of the Future.
     *
     * @param executorService ExecutorService to use to get the Future.
     * @param callable the callable to run in the new Future.
     * @param <RETVAL> the return type of the callable and Future.
     * @return a new Future representing asynchronous execution of the given callable.
     */
    public static <RETVAL> Future<RETVAL> getFuture(ExecutorService executorService, Callable<RETVAL> callable) {
        return executorService.submit(callable);
    }
}

Related

  1. executeLocally(Callable task)
  2. executeUntilNonNullOrTimeout(final long timeoutMs, final long timeBetweenPollsMs, final Callable callable)
  3. executeWithClassLoader(ClassLoader classLoader, Callable callable)
  4. expectException(Callable callable, Class exception)
  5. getBytes(final String string)
  6. getRandomValueForPrimitive(Class type)
  7. invokeAll(Collection> tasks, ExecutorService executorService)
  8. invokeBulkActions(Collection> tasks)
  9. max(final double[] a, final double[] b)