List of usage examples for java.lang Thread Thread
public Thread()
From source file:Main.java
static void persist(final SharedPreferences.Editor editor) { new Thread() { public void run() { editor.commit();/* w ww .ja v a 2 s . c om*/ } }.run(); }
From source file:Main.java
public static Thread runOnBackgroundThread(final Runnable runnable) { final Thread t = new Thread() { @Override//from w w w . java2 s . co m public void run() { runnable.run(); } }; t.start(); return t; }
From source file:com.adito.server.Main.java
/** * Entry point// w w w . ja v a 2 s .c om * * @param args * @throws Throwable */ public static void main(String[] args) throws Throwable { // This is a hack to allow the Install4J installer to get the java // runtime that will be used if (args.length > 0 && args[0].equals("--jvmdir")) { System.out.println(SystemProperties.get("java.home")); System.exit(0); } useWrapper = System.getProperty("wrapper.key") != null; final Main main = new Main(); ContextHolder.setContext(main); if (useWrapper) { WrapperManager.start(main, args); } else { Integer returnCode = main.start(args); if (returnCode != null) { if (main.gui) { if (main.startupException == null) { main.startupException = new Exception("An exit code of " + returnCode + " was returned."); } try { if (SystemProperties.get("os.name").toLowerCase().startsWith("windows")) { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } } catch (Exception e) { } String mesg = main.startupException.getMessage() == null ? "No message supplied." : main.startupException.getMessage(); StringBuffer buf = new StringBuffer(); int l = 0; char ch = ' '; for (int i = 0; i < mesg.length(); i++) { ch = mesg.charAt(i); if (l > 50 && ch == ' ') { buf.append("\n"); l = 0; } else { if (ch == '\n') { l = 0; } else { l++; } buf.append(ch); } } mesg = buf.toString(); final String fMesg = mesg; SwingUtilities.invokeAndWait(new Runnable() { public void run() { JOptionPane.showMessageDialog(null, fMesg, "Startup Error", JOptionPane.ERROR_MESSAGE); } }); } System.exit(returnCode.intValue()); } else { Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { if (!main.shuttingDown) { main.stop(0); } } }); } } }
From source file:Main.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private static void removeAllCookiesV21() { final CookieManager cookieManager = CookieManager.getInstance(); Looper looper = Looper.myLooper();//from w w w . j av a2 s.c o m boolean prepared = false; if (looper == null) { Looper.prepare(); prepared = true; } // requires a looper cookieManager.removeAllCookies(new ValueCallback<Boolean>() { @Override public void onReceiveValue(Boolean value) { Thread thread = new Thread() { @Override public void run() { // is synchronous, run in background cookieManager.flush(); } }; thread.start(); } }); if (prepared) { looper = Looper.myLooper(); if (looper != null) { looper.quit(); } } }
From source file:Main.java
public static CountDownLatch execute(int threadCount, final Runnable task) { final CountDownLatch startSignal = new CountDownLatch(1); final CountDownLatch startedSignal = new CountDownLatch(threadCount); final CountDownLatch doneSignal = new CountDownLatch(threadCount); for (int i = 0; i < threadCount; i++) { Thread t = new Thread() { public void run() { startedSignal.countDown(); try { startSignal.await(); } catch (InterruptedException e) { //ignore }//from ww w. j a v a2 s . c o m try { task.run(); } finally { doneSignal.countDown(); } } }; t.start(); } try { startedSignal.await(); } catch (InterruptedException e) { //ignore } startSignal.countDown(); return doneSignal; }
From source file:Main.java
public static void sleep(int milliseconds) { final int ms = milliseconds; Thread t = new Thread() { public void run() { try { sleep(ms);/*from w ww .j av a 2 s . co m*/ } catch (Exception e) { } } }; t.start(); try { t.join(); } catch (Exception e) { } }