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
/** * Executes a runnable piece of code, altering GUI components, which should be done on the EDT. If * the current thread is the EDT, the code is executed normally, otherwise it is wrapped in a * SwingUtilities.invokeLater(...)./*from w w w. j av a2 s. c om*/ * @param runnable The runnable to be executed on the EDT */ public static void executeWithEDTCheck(Runnable runnable) { if (SwingUtilities.isEventDispatchThread()) { runnable.run(); } else { SwingUtilities.invokeLater(runnable); } }
From source file:Main.java
public static ExecutorService immediateExecutorService() { return new AbstractExecutorService() { @Override/*from w w w . j a va 2 s . c o m*/ public void shutdown() { } @Override public List<Runnable> shutdownNow() { return null; } @Override public boolean isShutdown() { return false; } @Override public boolean isTerminated() { return false; } @Override public boolean awaitTermination(long l, TimeUnit timeUnit) throws InterruptedException { return false; } @Override public void execute(Runnable runnable) { runnable.run(); } }; }
From source file:Main.java
public static <T extends Throwable> T catchException(Class<T> exceptionClass, Runnable behavior) { Throwable caught = null;//ww w. ja va 2 s . c o m try { behavior.run(); } catch (Throwable ex) { caught = ex; } if (caught != null && exceptionClass.isAssignableFrom(caught.getClass())) //noinspection unchecked return (T) caught; return null; }
From source file:Main.java
public static void runInEdt(Runnable r) { if (SwingUtilities.isEventDispatchThread()) { r.run(); } else {/* w w w .j a v a 2s . c o m*/ SwingUtilities.invokeLater(r); } }
From source file:Main.java
public static void doSwing(Runnable r) { if (SwingUtilities.isEventDispatchThread()) { r.run(); } else {/*from w w w .j av a2 s . co m*/ try { SwingUtilities.invokeAndWait(r); } catch (InvocationTargetException e) { throw new RuntimeException(e); } catch (InterruptedException e) { throw new RuntimeException(e); } } }
From source file:Main.java
public static void runOnMain(final @NonNull Runnable runnable) { if (isMainThread()) runnable.run(); else//from w ww. j ava 2s . co m handler.post(runnable); }
From source file:Main.java
public static void runOnUiThread(final Runnable runnable) { if (Looper.myLooper() == Looper.getMainLooper()) { runnable.run(); } else {/*w w w . j a va 2 s . co m*/ new Handler(Looper.getMainLooper()).post(runnable); } }
From source file:Main.java
public static void runOnEventDispatchThread(Runnable runnable) { if (SwingUtilities.isEventDispatchThread()) { runnable.run(); } else/*from w w w . j a v a 2s . c om*/ try { SwingUtilities.invokeAndWait(runnable); } catch (InterruptedException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (InvocationTargetException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }
From source file:Main.java
public static void run(final String name, final Runnable r) { Thread t = new Thread(name) { public void run() { r.run(); }/*from w w w. j a v a 2s . c om*/ }; t.start(); }
From source file:Main.java
/** * Invoke and wait for the result. /* w ww . ja v a2 s . c om*/ */ public static void invokeAndWait(Runnable runnable) { if (SwingUtilities.isEventDispatchThread()) { runnable.run(); } else { try { SwingUtilities.invokeAndWait(runnable); } catch (InterruptedException e) { throw new RuntimeException("AWT queue job interrupted."); } catch (InvocationTargetException e) { throw new RuntimeException("Unhandled exception in the AWT event queue.", e.getCause()); } } }