Example usage for java.lang Runnable run

List of usage examples for java.lang Runnable run

Introduction

In this page you can find the example usage for java.lang Runnable run.

Prototype

public abstract void run();

Source Link

Document

When an object implementing interface Runnable is used to create a thread, starting the thread causes the object's run method to be called in that separately executing thread.

Usage

From source file:Main.java

/**
 * Invokes {@code run} immediately if this is the
 * EDT; otherwise, the {@code Runnable} is invoked
 * on the EDT using {@code invokeLater}.
 *///from w  w w .j  av  a  2 s  . co  m
public static void invokeNowOrLater(Runnable run) {
    if (SwingUtilities.isEventDispatchThread()) {
        run.run();
    } else {
        SwingUtilities.invokeLater(run);
    }
}

From source file:Main.java

/**
 * Run the runnable in EventDispatch Thread.
 * If the current thread is EventDispatch, it will run
 * immediately otherwise it will be queued in the DispatchThread
 * The difference with VFSManager.runInAWTThread() method is that
 * this one will not wait for IO Request before being executed
 *
 * @param runnable the runnable to run - it should return something meaningful from 
 *    toString() so that we can display it in the Task Monitor.
 *//*  ww w.j  a va2  s  .  com*/
public static void runInDispatchThread(Runnable runnable) {
    if (EventQueue.isDispatchThread())
        runnable.run();
    else
        EventQueue.invokeLater(runnable);
}

From source file:Main.java

/**
 * Executes a task in the main thread.<br>
 * If we are currently in the main thread, task will be executed immediately.
 * //from  ww w  . j  av  a 2s . c  o m
 * @param toExecute
 *            - task to execute.
 */
public static final void executeOnMain(final Runnable toExecute) {
    if (isMainThread()) {
        toExecute.run();
    } else {
        queueOnMain(toExecute, 0);
    }
}

From source file:Main.java

public static Future<?> timeout(long millis, Runnable runnable) {
    return POOL.submit(() -> {
        sleep(millis);//  www. j a v  a  2  s  .  c om
        runnable.run();
    });
}

From source file:Main.java

/**
 * If called from the FX Application Thread
 * invokes a runnable directly blocking the calling code
 * Otherwise//from   ww w.  j  av a2 s.c o m
 * uses Platform.runLater without blocking
 */
static void runOnFxThread(Runnable runnable) {
    if (Platform.isFxApplicationThread()) {
        runnable.run();
    } else {
        Platform.runLater(runnable);
    }
}

From source file:Main.java

/** 
 * Runs the task synchronously if the current thread is the event thread; otherwise passes it to the
 * event thread to be run asynchronously after all events already on the queue have been processed.
 *///w w  w  .j  a  va2  s.  com
public static void invokeLater(Runnable task) {
    if (EventQueue.isDispatchThread()) {
        task.run();
    } else {
        EventQueue.invokeLater(task);
    }
}

From source file:Main.java

public static void invokeAndWaitOrCry(final Runnable runnable) {

    if (SwingUtilities.isEventDispatchThread()) {
        runnable.run();
        return;/*w  ww.  jav  a  2  s  .co  m*/
    }

    try {
        SwingUtilities.invokeAndWait(runnable);
    } catch (final InterruptedException e) {
        throw new RuntimeException(e);
    } catch (final InvocationTargetException e) {
        throw new RuntimeException(e);
    }

}

From source file:Main.java

/**
 * Runs given runnable in dispatch thread.
 *//*from   w  w w  . j av  a 2s .  c  o m*/
public static void runInDispatchThread(final Runnable runnable) throws Exception {
    if (EventQueue.isDispatchThread()) {
        runnable.run();
    } else {
        EventQueue.invokeAndWait(runnable);
    }
}

From source file:Main.java

/**
 * Invokes the given Runnable in the AWT event dispatching thread, not
 * necessarily right away. This method may be called from any thread,
 * including the event dispatching thread itself.
 * @see SwingUtilities#invokeLater(Runnable)
 * @param runnable the Runnable to be executed.
 *//*w w  w .  j av  a 2s  . c  o  m*/
public static void invokeLater(Runnable runnable) {
    if (SwingUtilities.isEventDispatchThread()) {
        runnable.run();
    } else {
        SwingUtilities.invokeLater(runnable);
    }
}

From source file:Main.java

public final static void executeLaterInEDT(Runnable functor) {
    if (functor == null)
        return;/*from  ww  w. j  a v  a2 s .  c  o  m*/

    if (isInEDT()) {
        functor.run();
    } else {
        SwingUtilities.invokeLater(functor);
    }
}