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:edu.umn.msi.tropix.common.concurrent.impl.GrouppedFifoExecutorImpl.java
private static Runnable composeRunnables(final Runnable r1, final Runnable r2) { return new Runnable() { public void run() { try { r1.run(); } catch (final ShutdownException se) { throw se; } catch (final RuntimeException e) { ExceptionUtils.logQuietly(LOG, e); }//from w w w. j a v a2s . c o m r2.run(); } }; }
From source file:Main.java
/** * Execute the given {@link Runnable} on the ui thread. * * @param runnable The runnable to execute. *///from w w w. j a v a 2s.com public static void runOnUiThread(Runnable runnable) { Thread uiThread = Looper.getMainLooper().getThread(); if (Thread.currentThread() != uiThread) new Handler(Looper.getMainLooper()).post(runnable); else runnable.run(); }
From source file:com.atlassian.jira.rest.client.TestUtil.java
@SuppressWarnings("unused") public static <T extends Throwable> void assertThrows(Class<T> clazz, String regexp, Runnable runnable) { try {/*from ww w . j av a2 s .c om*/ runnable.run(); Assert.fail(clazz.getName() + " exception expected"); } catch (Throwable e) { Assert.assertTrue( "Expected exception of class " + clazz.getName() + " but was caught " + e.getClass().getName(), clazz.isInstance(e)); if (e.getMessage() == null && regexp != null) { Assert.fail("Exception with no message caught, while expected regexp [" + regexp + "]"); } if (regexp != null && e.getMessage() != null) { Assert.assertTrue("Message [" + e.getMessage() + "] does not match regexp [" + regexp + "]", e.getMessage().matches(regexp)); } } }
From source file:io.dyn.core.Tasks.java
public static void execute(Runnable r, TaskExecutor te) { if (null != te && te != CURRENT_EXECUTOR.get()) { te.execute(r);// ww w. jav a2 s .com } else { r.run(); } }
From source file:com.sf.ddao.TxHelper.java
public static <SK> void execInTx(TransactionableDao dao, final Runnable runnable, SK... shardKeys) throws Exception { execInTx(dao, new Callable<Object>() { public Object call() throws Exception { runnable.run(); return null; }// w w w . ja v a 2 s.c o m }, shardKeys); }
From source file:Main.java
public static void runAndWait(Runnable action) { if (action == null) throw new NullPointerException("action"); // run synchronously on JavaFX thread if (Platform.isFxApplicationThread()) { action.run(); return;/*from w ww . jav a2 s .c o m*/ } // queue on JavaFX thread and wait for completion final CountDownLatch doneLatch = new CountDownLatch(1); Platform.runLater(() -> { try { action.run(); } finally { doneLatch.countDown(); } }); try { doneLatch.await(); } catch (InterruptedException e) { // ignore exception } }
From source file:com.atlassian.jira.rest.client.TestUtil.java
public static void assertErrorCode(int errorCode, String message, Runnable runnable) { try {/* w w w .j a v a2s. c o m*/ runnable.run(); Assert.fail(RestClientException.class + " exception expected"); } catch (com.atlassian.jira.rest.client.api.RestClientException e) { Assert.assertTrue(e.getStatusCode().isPresent()); Assert.assertEquals(errorCode, e.getStatusCode().get().intValue()); if (!StringUtils.isEmpty(message)) { // We expect a single error message. Either error or error message. Assert.assertEquals(1, e.getErrorCollections().size()); if (Iterators.getOnlyElement(e.getErrorCollections().iterator()).getErrorMessages().size() > 0) { Assert.assertEquals(getOnlyElement( getOnlyElement(e.getErrorCollections().iterator()).getErrorMessages().iterator()), message); } else if (Iterators.getOnlyElement(e.getErrorCollections().iterator()).getErrors().size() > 0) { Assert.assertEquals(getOnlyElement( getOnlyElement(e.getErrorCollections().iterator()).getErrors().values().iterator()), message); } else { Assert.fail("Expected an error message."); } } } }
From source file:Main.java
/** * Runs arbitrary code in the Event Dispatch Thread. * /*from w w w .j a va 2 s . c o m*/ * @param runnable the {@code Runnable} to run in the Event Dispatch Thread */ public static void runInEDT(final Runnable runnable) { if (runnable != null) { if (SwingUtilities.isEventDispatchThread()) { runnable.run(); } else { invokeAndWait(runnable); } } }
From source file:com.haulmont.cuba.desktop.sys.validation.ValidationAlertHolder.java
public static void runIfValid(Runnable r) { validationExpected();//from www . j av a 2 s . c o m try { DesktopComponentsHelper.flushCurrentInputField(); if (!isFailed()) { clear(); r.run(); } } finally { clear(); } }
From source file:Main.java
public static void scaleHide(final View view, final Runnable rWhenEnd) { if (view.getWindowToken() == null) { view.setVisibility(View.INVISIBLE); if (rWhenEnd != null) { rWhenEnd.run(); }/*from w w w.j ava 2 s .c o m*/ return; } ObjectAnimator scaleX = ObjectAnimator.ofFloat(view, "scaleX", 1f, 0f); ObjectAnimator scaleY = ObjectAnimator.ofFloat(view, "scaleY", 1f, 0f); AnimatorSet set = new AnimatorSet(); set.playTogether(scaleX, scaleY); set.setDuration(DURATION_SHORT); set.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { view.setVisibility(View.INVISIBLE); if (rWhenEnd != null) { rWhenEnd.run(); } } @Override public void onAnimationCancel(Animator animation) { view.setVisibility(View.INVISIBLE); if (rWhenEnd != null) { rWhenEnd.run(); } } @Override public void onAnimationRepeat(Animator animation) { } }); set.start(); }