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
/** * Thread-friendly wrapper method for <code>AbstractButton.setSelected</code>. * @param selected/*w ww .j av a2 s. com*/ * @param buttons AbstractButtons to select/deselect * * @see javax.swing.AbstractButton.setSelected(boolean) * @deprecated */ @Deprecated public static void setSelected(final boolean selected, final AbstractButton... buttons) { Runnable r = new Runnable() { public void run() { for (AbstractButton button : buttons) { button.setSelected(selected); } } }; if (EventQueue.isDispatchThread()) { r.run(); return; } runTask(r, true); }
From source file:com.yihaodian.architecture.zkclient.TestUtil.java
/** * This waits until a mockito verification passed (which is provided in the runnable). This waits until the * virification passed or the timeout has been reached. If the timeout has been reached this method will rethrow the * {@link MockitoAssertionError} that comes from the mockito verification code. * //from w w w . ja v a 2 s . c o m * @param runnable * The runnable containing the mockito verification. * @param timeUnit * The timeout timeunit. * @param timeout * The timeout. * @throws InterruptedException */ public static void waitUntilVerified(Runnable runnable, TimeUnit timeUnit, int timeout) throws InterruptedException { long startTime = System.currentTimeMillis(); do { MockitoAssertionError exception = null; try { runnable.run(); } catch (MockitoAssertionError e) { exception = e; } if (exception == null) { return; } if (System.currentTimeMillis() > startTime + timeUnit.toMillis(timeout)) { throw exception; } Thread.sleep(50); } while (true); }
From source file:Main.java
/** * If runOnEDT is true will execute the thread on the Event Dispatch Thread * Otherwise it will use a SwingWorker// w ww . j av a 2 s .c o m * @param r <code>Runnable</code> to execute * @param runOnEDT run on Event Dispatching Thread * * @see javax.swing.SwingWorker * @see java.lang.Runnable * @deprecated */ @Deprecated public static void runTask(final Runnable r, boolean runOnEDT) { if (runOnEDT) { SwingUtilities.invokeLater(r); return; } SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { r.run(); return null; } }; worker.execute(); }
From source file:controllers.AbstractPostingApp.java
public static Result saveComment(final Comment comment, Form<? extends Comment> commentForm, final Call toView, Runnable containerUpdater) { if (commentForm.hasErrors()) { flash(Constants.WARNING, "post.comment.empty"); return redirect(toView); }/*from w ww. j a va 2 s . c o m*/ containerUpdater.run(); // this updates comment.issue or comment.posting; if (comment.id != null && AccessControl.isAllowed(UserApp.currentUser(), comment.asResource(), Operation.UPDATE)) { comment.update(); } else { comment.setAuthor(UserApp.currentUser()); comment.save(); } // Attach all of the files in the current user's temporary storage. attachUploadFilesToPost(comment.asResource()); String urlToView = RouteUtil.getUrl(comment); NotificationEvent.afterNewComment(comment); return redirect(urlToView); }
From source file:Main.java
/** Runs a piece of code after the next layout run */ public static void doAfterLayout(final View view, final Runnable runnable) { final OnGlobalLayoutListener listener = new OnGlobalLayoutListener() { @Override/* w w w . ja v a 2s . co m*/ public void onGlobalLayout() { // Layout pass done, unregister for further events view.getViewTreeObserver().removeOnGlobalLayoutListener(this); runnable.run(); } }; view.getViewTreeObserver().addOnGlobalLayoutListener(listener); }
From source file:Main.java
public static void onShown(final JComponent component, final Runnable action) { component.addHierarchyListener(new HierarchyListener() { public void hierarchyChanged(final HierarchyEvent e) { if (e.getComponent() == component && (e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) > 0) { if (component.isShowing()) action.run(); }/*from w w w . j a v a 2 s. c o m*/ } }); }
From source file:com.android.browser.GoogleAccountLogin.java
public static void startLoginIfNeeded(Activity activity, Runnable runnable) { // Already logged in? if (isLoggedIn()) { runnable.run(); return;/*from w w w.ja va 2 s .c o m*/ } // No account found? Account[] accounts = getAccounts(activity); if (accounts == null || accounts.length == 0) { runnable.run(); return; } GoogleAccountLogin login = new GoogleAccountLogin(activity, accounts[0], runnable); login.startLogin(); }
From source file:fi.hsl.parkandride.core.service.UserServiceTest.java
private static void assertAccessDenied(Runnable r) { try {/*from w ww. ja va2 s . c o m*/ r.run(); Assert.fail("did not throw AccessDeniedException"); } catch (AccessDeniedException expected) { } }
From source file:com.netflix.iep.gov.Governator.java
/** Add a task to be executed after shutting down governator. */ public static void addShutdownHook(final Runnable task) { final Runnable r = new Runnable() { @Override/*from www . ja v a2s.c o m*/ public void run() { try { getInstance().shutdown(); task.run(); } catch (Exception e) { LOGGER.warn("exception during shutdown sequence", e); } } }; Runtime.getRuntime().addShutdownHook(new Thread(r, "ShutdownHook")); }
From source file:org.vader.common.spring.TransactionScope.java
private static void registerSynchronization() { LOG.debug("Registers transaction synchronization"); TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() { @Override/*w ww. java 2 s. co m*/ public void suspend() { LOG.debug("Push new transaction scope"); SCOPES.get().push(new HashMap<String, ScopeEntry>()); } @Override public void resume() { LOG.debug("Pop old transaction scope"); SCOPES.get().pop(); } @Override public void afterCompletion(int status) { final Map<String, ScopeEntry> scope = getCurrentScope(); LOG.debug("Destroying {} beans", scope.size()); for (Map.Entry<String, ScopeEntry> entry : scope.entrySet()) { for (Runnable runnable : entry.getValue().getCallbacks()) { LOG.debug("Executes destruction callback for bean={}", entry.getKey()); runnable.run(); } } scope.clear(); LOG.debug("Destruction completed"); } }); }