List of usage examples for java.lang Runnable run
public abstract void run();
Runnable
is used to create a thread, starting the thread causes the object's run
method to be called in that separately executing thread. From source file:Main.java
public static void invokeLater(Runnable r) { if (!ignoreInvokeLater) { SwingUtilities.invokeLater(r); } else {/*ww w . j a va 2s . c o m*/ r.run(); } }
From source file:Main.java
/** * Execute {@code doRun} in the EDT. The calling thread does NOT wait for * the completion of {@code doRun}.//from w w w . j av a2s.c o m * * This method use internally * {@link javax.swing.SwingUtilities#invokeLater(Runnable)}, so any * exception thrown during the execution of {@code doRun} is caught in the * EDT. * * @param doRun * {@code Runnable} to be run. * */ public static void invokeLater(Runnable doRun) { if (SwingUtilities.isEventDispatchThread()) { doRun.run(); } else { SwingUtilities.invokeLater(doRun); } }
From source file:Main.java
public static void callOnMainThread(Runnable runnable) { if (!isMainThread()) { sHandler.post(runnable);//from w ww . ja v a 2s . c o m return; } runnable.run(); }
From source file:Main.java
public static final void invokeInAWTThread(Runnable r, boolean wait) { if (SwingUtilities.isEventDispatchThread()) { r.run(); } else {// ww w. j av a2s . c o m if (wait) { try { SwingUtilities.invokeAndWait(r); } catch (Exception ex) { } } else { SwingUtilities.invokeLater(r); } } }
From source file:Main.java
/** * Causes runnable to have its run method called in the dispatch thread of * the event queue. This will happen after all pending events are processed. * The call blocks until this has happened. *///from w ww . java 2s . c o m public static void invokeAndWait(final Runnable runnable) { if (EventQueue.isDispatchThread()) { runnable.run(); } else { try { EventQueue.invokeAndWait(runnable); } catch (InterruptedException exception) { // Someone don't want to let us sleep. Go back to work. } catch (InvocationTargetException target) { final Throwable exception = target.getTargetException(); if (exception instanceof RuntimeException) { throw (RuntimeException) exception; } if (exception instanceof Error) { throw (Error) exception; } // Should not happen, since {@link Runnable#run} do not allow checked exception. throw new UndeclaredThrowableException(exception, exception.getLocalizedMessage()); } } }
From source file:Main.java
/** * Method to clarify, that invoking {@code Runnable#run()} is really intented. This also prevents IDEs and other * tools from showing warnings./*from ww w. j a v a2s. com*/ * * @param runnable */ public static void runInThisThread(Runnable runnable) { if (runnable == null) { throw new NullPointerException("runnable == null"); } runnable.run(); }
From source file:Main.java
public static void dispatchPendingRunnables() { for (int i = RUNNABLES_PER_FRAME; i > 0; i--) { Runnable job = jobs.poll(); if (job == null) { return; }//from ww w . jav a2s. co m job.run(); } }
From source file:Main.java
public static void runOnSwingThread(Runnable run) { if (javax.swing.SwingUtilities.isEventDispatchThread()) { run.run(); } else {/*from w w w . j av a 2 s. c o m*/ runOnSwingThreadLater(run); } }
From source file:Main.java
public static void runActionLater(final Runnable runnable) { if (Platform.isFxApplicationThread()) { runnable.run(); } else {/*from w w w . j a v a 2s.c om*/ try { uiSemaphore.acquire(); Platform.runLater(() -> { try { runnable.run(); releaseUiSemaphor(); } catch (Exception e) { releaseUiSemaphor(); throw new RuntimeException(e); } }); } catch (Exception e) { releaseUiSemaphor(); throw new RuntimeException(e); } } }
From source file:Main.java
public static void runOnMainSync(final @NonNull Runnable runnable) { if (isMainThread()) { runnable.run(); } else {// w ww. j a v a2 s .c o m final CountDownLatch sync = new CountDownLatch(1); runOnMain(new Runnable() { @Override public void run() { try { runnable.run(); } finally { sync.countDown(); } } }); try { sync.await(); } catch (InterruptedException ie) { throw new AssertionError(ie); } } }