private static void doJoinAll(final Task[] tasks, final long timeout, final boolean joinUI) throws InterruptedException, CancellationException, ExecutionException, TimeoutException { if (tasks == null) { throw new IllegalArgumentException("Can not joinAll(), list of tasks to join is null"); } if (timeout < 0) { throw new IllegalArgumentException("Can not joinAll() with timeout < 0: timeout=" + timeout); } // #mdebug if (PlatformUtils.isUIThread() && timeout > 100) { L.i("WARNING- slow Task.joinAll() on UI Thread", "timeout=" + timeout); } // #enddebug // #debug L.i("Start joinAll(" + timeout + ")", "numberOfTasks=" + tasks.length); long timeLeft = Long.MAX_VALUE; try { final long startTime = System.currentTimeMillis(); for (int i = 0; i < tasks.length; i++) { final Task task = tasks[i]; timeLeft = startTime + timeout - System.currentTimeMillis(); if (timeLeft <= 0) { throw new TimeoutException("joinAll(" + timeout + ") timout exceeded (" + timeLeft + ")"); } if (joinUI && task instanceof UITask) { task.joinUI(timeout); } else { task.join(timeout); } } } finally { // #debug L.i( "End joinAll(" + timeout + ")", "numberOfTasks=" + tasks.length + " timeElapsed=" + (timeout - timeLeft)); } }