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:de.longri.cachebox3.Utils.java
public static void logRunningTime(final String name, Runnable runnable) { long start = System.currentTimeMillis(); runnable.run(); long runningTime = System.currentTimeMillis() - start; log.info(("Time for " + name + ": " + Long.toString(runningTime))); }
From source file:com.raphfrk.craftproxyclient.gui.GUIManager.java
public static JSONObject getPreviousLoginDetails() { JSONObject loginInfo = AuthManager.refreshAccessToken(); if (loginInfo == null) { return null; }//from w ww . ja va 2 s. co m final AtomicInteger option = new AtomicInteger(); Runnable r = new Runnable() { public void run() { option.set(JOptionPane.showConfirmDialog(CraftProxyClient.getGUI(), "Login as " + AuthManager.getUsername() + "?", "Login", JOptionPane.YES_NO_OPTION)); } }; if (SwingUtilities.isEventDispatchThread()) { r.run(); } else { try { SwingUtilities.invokeAndWait(r); } catch (InvocationTargetException | InterruptedException e) { return null; } } if (option.get() == 0) { return loginInfo; } else { return null; } }
From source file:com.kaching.platform.common.logging.Log.java
public static void withLogContext(Runnable runnable, Pair<String, Object>... contexts) { try {//from w w w . j a v a2 s.c o m for (Pair<String, Object> context : contexts) { logContextPut(context.left, context.right); } runnable.run(); } finally { for (Pair<String, Object> context : contexts) { logContextRemove(context.left); } } }
From source file:Main.java
public static void makeAboutSpannable(SpannableStringBuilder span, String str_link, String replace, final Runnable on_click) { Pattern pattern = Pattern.compile(str_link); Matcher matcher = pattern.matcher(span); ForegroundColorSpan color_theme = new ForegroundColorSpan(Color.parseColor("#53b7bb")); if (matcher.find()) { span.setSpan(new ClickableSpan() { @Override/*from w ww .j a v a 2 s . c o m*/ public void onClick(View widget) { if (on_click != null) on_click.run(); } }, matcher.start(), matcher.end(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); span.setSpan(color_theme, matcher.start(), matcher.end(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); if (replace != null) span.replace(matcher.start(), matcher.end(), replace); } }
From source file:de.codesourcery.jasm16.ide.ui.utils.UIUtils.java
public static void invokeLater(Runnable r) { if (SwingUtilities.isEventDispatchThread()) { r.run(); } else {// w ww .j a v a 2 s . co m SwingUtilities.invokeLater(r); } }
From source file:rdfconnection.RDFConnectionRemote.java
/** Convert HTTP status codes to exceptions */ static void exec(Runnable action) { try {/*from w ww. j a v a 2 s . c o m*/ action.run(); } catch (HttpException ex) { handleHttpException(ex, false); } }
From source file:de.codesourcery.jasm16.ide.ui.utils.UIUtils.java
public static void invokeAndWait(Runnable r) { if (SwingUtilities.isEventDispatchThread()) { r.run(); } else {/*w w w . j a v a 2 s. co m*/ try { SwingUtilities.invokeAndWait(r); } catch (InvocationTargetException e) { throw new RuntimeException(e.getCause()); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } }
From source file:Main.java
/** * Runs the specified runnable in the EDT using * <code>SwingUtilities.invokeAndWait(...)</code>. * Note: This method 'supresses' the method's thrown exceptions * - InvocationTargetException and InterruptedException. * * @param runnable - the runnable to be executed *//*ww w . jav a 2 s. co m*/ public static void invokeAndWait(Runnable runnable) { if (!SwingUtilities.isEventDispatchThread()) { try { //System.err.println("Not EDT"); SwingUtilities.invokeAndWait(runnable); } catch (InterruptedException e) { // nothing to do here } catch (InvocationTargetException e) { // nothing to do here } } else { runnable.run(); } }
From source file:com.taxicop.client.NetworkUtilities.java
public static Thread performOnBackgroundThread(final Runnable runnable) { final Thread t = new Thread() { @Override/* ww w . j av a 2 s .co m*/ public void run() { try { runnable.run(); } finally { } } }; t.start(); return t; }
From source file:Main.java
public static void createCancellableAcceptDialog(Context context, String title, String message, String acceptButtonText, final Runnable onAccept) { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(title);//from w w w . ja v a2 s. co m builder.setMessage(message); builder.setInverseBackgroundForced(true); builder.setPositiveButton(acceptButtonText, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); if (onAccept != null) onAccept.run(); } }); AlertDialog alert = builder.create(); alert.show(); }