List of usage examples for java.lang Thread join
public final void join() throws InterruptedException
From source file:Main.java
public static void joinForSure(Thread thread) { while (true) { try {//from w w w. j a v a 2 s . c o m thread.join(); break; } catch (InterruptedException e) { } } }
From source file:Main.java
public static void interruptThreadAndJoin(Thread thread) { thread.interrupt();// w w w . j a va 2 s .c o m try { thread.join(); } catch (InterruptedException e) { /* Ignore */ } }
From source file:com.google.appengine.tck.byteman.ConcurrentTxTestBase.java
protected static void join(Iterable<Thread> threads) throws Exception { for (Thread thread : threads) { thread.join(); }/*from w w w. j ava 2s.c o m*/ }
From source file:Main.java
public final static void joinQuietly(Thread t) { join: do {/* www .ja va 2 s . c o m*/ try { t.join(); } catch (InterruptedException e) { continue join; } } while (false); }
From source file:Main.java
/** * Wait for all threads with the specified name to finish, i.e. to not appear in the * list of running threads any more./*from w w w . j av a2 s. c o m*/ * * @param name * * @throws InterruptedException * @author dominik.stadler */ public static void waitForThreadToFinish(final String name) throws InterruptedException { int count = Thread.currentThread().getThreadGroup().activeCount(); Thread[] threads = new Thread[count]; Thread.currentThread().getThreadGroup().enumerate(threads); for (Thread t : threads) { if (t != null && name.equals(t.getName())) { t.join(); } } }
From source file:Main.java
/** * Wait for thread whose name contain the specified string to finish, i.e. to not appear in the * list of running threads any more./*ww w .ja v a 2s .com*/ * * @param name * * @throws InterruptedException * @author dominik.stadler */ public static void waitForThreadToFinishSubstring(final String name) throws InterruptedException { int count = Thread.currentThread().getThreadGroup().activeCount(); Thread[] threads = new Thread[count]; Thread.currentThread().getThreadGroup().enumerate(threads); for (Thread t : threads) { if (t != null && t.getName().contains(name)) { t.join(); } } }
From source file:Main.java
public static void joinUninterruptibly(Thread t) { boolean interrupted = false; while (t.isAlive()) { try {/*from w w w . j av a2 s . c om*/ t.join(); } catch (InterruptedException e) { interrupted = true; } } if (interrupted) { Thread.currentThread().interrupt(); } }
From source file:Main.java
public static void tillDies(Thread thread) { if (thread != null) { for (;;) { try { thread.join(); break; } catch (InterruptedException ignore) { }/* www . j a va 2 s . c o m*/ } } }
From source file:Main.java
/** * For testing only - prevent the tests to exit until all thread finished *///from www . j a v a 2 s . c om public static void waitForBackgroundThreads() { Enumeration e = threads.elements(); while (e.hasMoreElements()) { Thread thread = (Thread) e.nextElement(); if (thread.isAlive()) { try { thread.join(); } catch (InterruptedException ignore) { ignore.printStackTrace(); } } } }
From source file:Main.java
public static void runInThread(final Runnable runnable) throws Throwable { final AtomicReference<Throwable> exception = new AtomicReference<Throwable>(); Runnable exceptionGuard = new Runnable() { public void run() { try { runnable.run();/*from w w w. j a va2 s . com*/ } catch (Throwable throwable) { exception.set(throwable); } } }; Thread thread = new Thread(exceptionGuard); thread.setDaemon(true); thread.start(); thread.join(); if (exception.get() != null) { throw exception.get(); } }