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

public static Thread performOnBackgroundThread(final Runnable runnable) {
    final Thread t = new Thread() {
        @Override// w  w w .j a  va2 s  .com
        public void run() {
            runnable.run();
        }
    };
    t.start();
    return t;
}

From source file:com.willwinder.universalgcodesender.utils.GUIHelpers.java

public static void invokeLater(Runnable r) {
    if (unitTestMode) {
        r.run();
    } else {/*from   w  ww .ja v a  2 s.co m*/
        java.awt.EventQueue.invokeLater(r);
    }
}

From source file:Main.java

/**
 * Utility method used to run, synchronously, a Runnable on the main thread. Behaves exactly
 * like {@link EventQueue#invokeAndWait(Runnable)}, but can be called from the main thread as
 * well./*  w  ww  .  ja v  a 2  s  . com*/
 * 
 * @param runnable
 * @throws InterruptedException
 * @throws InvocationTargetException
 */
public static void invokeAndWait(Runnable runnable) throws InvocationTargetException, InterruptedException {
    if (EventQueue.isDispatchThread()) {
        runnable.run();
    } else {
        EventQueue.invokeAndWait(runnable);
    }
}

From source file:Main.java

static public void runOnFxThread(final Runnable run) {
    if (javafx.application.Platform.isFxApplicationThread()) {
        run.run();
    } else {//from ww  w  . jav a  2 s. c o  m
        runOnFxThreadLater(run);
    }
}

From source file:Main.java

public static void doInBackground(final Runnable r) {
    new SwingWorker<Void, Void>() {
        @Override/*from  w  w  w .j  a va2  s.co m*/
        protected Void doInBackground() {
            r.run();
            return null;
        }
    }.execute();
}

From source file:Main.java

/**
 * Invokes the runnable within the EDT//from   ww  w. ja v  a2 s  . co  m
 *
 * @param runnable a Runnable object.
 */
public static void invokeInEventDispatchThread(@Nonnull Runnable runnable) {
    if (isEventDispatchThread()) {
        runnable.run();
    } else {
        try {
            SwingUtilities.invokeAndWait(runnable);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        } catch (InvocationTargetException e) {
            Throwable targetException = e.getTargetException();
            if (targetException instanceof RuntimeException) {
                throw (RuntimeException) targetException;
            }
            //noinspection ThrowInsideCatchBlockWhichIgnoresCaughtException
            throw new RuntimeException(targetException);
        }
    }
}

From source file:com.yahoo.validatar.OutputCaptor.java

public static void runWithoutOutput(Runnable function) {
    redirectToDevNull();
    function.run();
    redirectToStandard();
}

From source file:Main.java

/**
 * Invoke "runnable" on the AWT event dispatching thread.<br>
 * If you are in the AWT event dispatching thread the runnable can be executed immediately<br>
 * depending the value of <code>forceLater</code> parameter.
 * /*from w w  w.  j  a  v a 2s.co  m*/
 * @param forceLater
 *        Force execution of runnable to be delayed<br>
 *        even if we are on the AWT event dispatching thread
 */
public static void invokeLater(Runnable runnable, boolean forceLater) {
    if (SwingUtilities.isEventDispatchThread() && !forceLater)
        runnable.run();
    else
        SwingUtilities.invokeLater(runnable);
}

From source file:Main.java

public static ActionListener getActionListenerForRunnable(final Runnable runnable) {
    return new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            runnable.run();
        }//from w w w.  j av a 2 s  .c o  m
    };
}

From source file:Main.java

public static void runTaskLater(Runnable runnable) {
    Task task = new Task() {
        @Override// ww  w  . j  a  v  a  2 s .  com
        protected Object call() throws Exception {
            runnable.run();
            return null;
        }
    };

    new Thread(task).start();

}