package nl.uu.cs.tbijlsma.concjmeta; /** * Re-implements Thread.join() in instrumentable code. */ public final class Join { private Join() { } public static void join(Thread t) throws InterruptedException { join(t, 0); } public static void join(Thread t, long millis, int nanos) throws InterruptedException { if (nanos >= 500000 || (nanos != 0 && millis == 0)) { millis++; } join(t, millis); } public static void join(Thread t, long millis) throws InterruptedException { synchronized (t) { if (millis < 0) { throw new IllegalArgumentException("timeout value is negative"); } long base = System.currentTimeMillis(); long now = 0; if (millis == 0) { while (t.isAlive()) { /* StackTraceElement[] trace = t.getStackTrace(); for (StackTraceElement ste : trace) { System.err.println(ste); } */ t.wait(0); } } else { while (t.isAlive()) { long delay = millis - now; if (delay <= 0) { break; } t.wait(delay); now = System.currentTimeMillis() - base; } } } } }