Example usage for java.util.concurrent FutureTask FutureTask

List of usage examples for java.util.concurrent FutureTask FutureTask

Introduction

In this page you can find the example usage for java.util.concurrent FutureTask FutureTask.

Prototype

public FutureTask(Runnable runnable, V result) 

Source Link

Document

Creates a FutureTask that will, upon running, execute the given Runnable , and arrange that get will return the given result on successful completion.

Usage

From source file:Main.java

@SuppressWarnings({ "unchecked", "rawtypes" })
public static void runAndWait(Runnable runnable) throws InterruptedException, ExecutionException {
    FutureTask<?> future = new FutureTask(runnable, null);
    Platform.runLater(future);/*w ww .  ja  v a  2s . co  m*/
    future.get();
}

From source file:Main.java

public static void runInNewThread(String threadName, Runnable target) throws Throwable {
    FutureTask<Object> future = new FutureTask<Object>(target, null);
    new Thread(future, threadName).start();
    try {//w  w w.  jav a2 s  . c  om
        future.get();
    } catch (ExecutionException e) {
        throw e.getCause();
    }
}

From source file:Main.java

/**
 * Run the supplied Runnable on the main thread. The method will block until the Runnable
 * completes./*from ww w .  ja va  2s  .c  o  m*/
 *
 * @param r The Runnable to run.
 */
public static void runOnUiThreadBlocking(final Runnable r) {
    if (runningOnUiThread()) {
        r.run();
    } else {
        FutureTask<Void> task = new FutureTask<Void>(r, null);
        postOnUiThread(task);
        try {
            task.get();
        } catch (Exception e) {
            throw new RuntimeException("Exception occured while waiting for runnable", e);
        }
    }
}

From source file:Main.java

/**
 * Runs the given <tt>Runnable</tt> on the JavaFX Application Thread. The method blocks until the <tt>Runnable</tt> is executed completely.
 * You should use the {@link io.datafx.core.concurrent.ProcessChain} for concurrent tasks and background tasks
 * instead of using this low level API.//from  w  ww  . j ava  2  s .co m
 *
 *
 * @param runnable the runnable that will be executed on the JavaFX Application Thread
 * @throws InterruptedException if the JavaFX Application Thread was interrupted while waiting
 * @throws ExecutionException   if the call of the run method of the <tt>Runnable</tt> threw an exception
 */
public static void runAndWait(Runnable runnable) throws InterruptedException, ExecutionException {
    FutureTask<Void> future = new FutureTask<>(runnable, null);
    Platform.runLater(future);
    future.get();
}

From source file:MainClass.java

public void invokeAneWait(Runnable r) throws InterruptedException, ExecutionException {
    FutureTask task = new FutureTask(r, null);
    tpe.execute(task);/*w  w  w  . ja  v  a  2s .c om*/
    task.get();
}

From source file:net.sf.jvifm.util.AutoCompleteUtil.java

public static void initSysExeNameList() {
    Runnable loader = new Runnable() {
        public void run() {
            _initSysExeNameList();/*  w  ww.  j  a va2s. com*/
        }
    };
    ft = new FutureTask<String>(loader, "ok");
    es.submit(ft);
}

From source file:Main.java

/**
 * Submits a Runnable task for execution on the EDT and returns a
 * Future representing that task.//from   w  ww. j a  va  2  s  . c  o  m
 *
 * @param task the task to submit
 * @param result the result to return upon successful completion
 * @return a Future representing pending completion of the task,
 *         and whose <tt>get()</tt> method will return the given
 *         result value upon completion
 * @throws NullPointerException if the task is null
 */
public static <V> Future<V> submit(Runnable task, V result) {
    if (task == null) {
        throw new NullPointerException();
    }
    FutureTask<V> future = new FutureTask<V>(task, result);
    execute(future);
    return future;
}

From source file:org.luwrain.app.commander.Base.java

void launch(FilesOperation op) {
    NullCheck.notNull(op, "op");
    operations.add(op);
    luwrain.executeBkg(new FutureTask(op, null));
}

From source file:com.saysth.commons.quartz.SimpleThreadPoolTaskExecutor.java

public Future<?> submit(Runnable task) {
    FutureTask<Object> future = new FutureTask<Object>(task, null);
    execute(future);//  ww  w  . j  av a2  s .  co  m
    return future;
}

From source file:org.jactr.core.module.AbstractModule.java

static public <T> Future<T> immediateReturn(T value) {
    FutureTask<T> ft = new FutureTask<T>(new Runnable() {
        public void run() {
            // noop
        }/*from   ww w  .  j  av a2s . c  o  m*/
    }, value);
    ft.run();
    return ft;
}