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
/** * The runnable is responsible for leaving the nested event loop. *//*from www . j a va2s .co m*/ static void runOnEDTAndWait(Object nestedLoopKey, Runnable r) { Toolkit.getToolkit().checkFxUserThread(); if (SwingUtilities.isEventDispatchThread()) { r.run(); } else { eventLoopKeys.add(nestedLoopKey); SwingUtilities.invokeLater(r); Toolkit.getToolkit().enterNestedEventLoop(nestedLoopKey); } }
From source file:com.calamp.services.kinesis.events.writer.CalAmpEventWriter.java
public static void runningLoop(Runnable exec) { while (true) { exec.run(); } }
From source file:Main.java
public static void runOnUiThread(final Runnable runnable) { if (Looper.myLooper() != Looper.getMainLooper()) { new Handler(Looper.getMainLooper()).post(runnable); } else {/* w ww . ja va2 s . com*/ runnable.run(); } }
From source file:Main.java
public static void runAsync(final Runnable r) { new AsyncTask<Void, Void, Void>() { @Override/* ww w.j ava 2 s. co m*/ protected Void doInBackground(Void... unused) { r.run(); return null; } }.execute(); }
From source file:io.appium.java_client.pagefactory_tests.TimeoutTest.java
private static long getPerformanceDiff(long expectedMs, Runnable runnable) { long startMark = currentTimeMillis(); runnable.run(); long endMark = currentTimeMillis(); return abs(expectedMs - (endMark - startMark)); }
From source file:Main.java
public static void onCheckBoxChange(JCheckBox field, final Runnable task) { field.addActionListener(new ActionListener() { @Override// www . j av a 2s .c om public void actionPerformed(ActionEvent e) { task.run(); } }); }
From source file:Main.java
/** * Run the supplied Runnable on the main thread. The method will block only if the current * thread is the main thread.//from w w w . j ava 2 s. c o m * * @param r The Runnable to run */ public static void runOnUiThread(Runnable r) { if (runningOnUiThread()) { r.run(); } else { getUiThreadHandler().post(r); } }
From source file:Main.java
/** * Causes <code>runnable</code> to have its <code>run</code> method called * in the dispatch thread of {@link Toolkit#getSystemEventQueue the system * EventQueue} if this method is not being called from it. This will happen * after all pending events are processed. * /*from www. j a va 2 s .c o m*/ * @param runnable * the <code>Runnable</code> whose <code>run</code> method should * be executed synchronously on the <code>EventQueue</code> */ public static void invokeOnEdt(Runnable runnable) { boolean isEdt = EventQueue.isDispatchThread(); if (!isEdt) { EventQueue.invokeLater(runnable); } else { runnable.run(); } }
From source file:Main.java
public static void invokeInAwtEventQueue(final Runnable runnable) { if (!isEventDispatchThread()) invokeLater(new Runnable() { public void run() { runnable.run(); }//from w w w . j a va 2 s . c om }); else runnable.run(); }
From source file:Main.java
public static void alphaHide(@NonNull final View view, final Runnable rWhenDone) { if (view.getWindowToken() == null) { if (rWhenDone != null) rWhenDone.run(); return;//from w w w. j av a 2 s .c o m } ObjectAnimator alpha = ObjectAnimator.ofFloat(view, "alpha", 1f, 0f); alpha.setDuration(DURATION_MID); alpha.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { view.setVisibility(View.INVISIBLE); if (rWhenDone != null) rWhenDone.run(); } @Override public void onAnimationCancel(Animator animation) { view.setVisibility(View.INVISIBLE); if (rWhenDone != null) rWhenDone.run(); } @Override public void onAnimationRepeat(Animator animation) { } }); alpha.start(); }