class TaskManager implements TaskListener<Task> {

    public static void startAndWait(final Task task)
            throws InterruptedException {
        if (task == null) {
            return;
        }
        TaskTerminationWaiter taskTerminationWaiter = new TaskTerminationWaiter(
                task);
        task.addTaskListener(taskTerminationWaiter);
        if (task.getState().isRunning() == false) {
            task.start(new Thread.UncaughtExceptionHandler() {
                @Override
                public void uncaughtException(Thread th, Throwable ex) {
                    logger.error("Uncaught exception from task "
                            + task.getName() + ": " + ex);
                    ex.printStackTrace();
                }
            });
        }
        while (task.getState().isRunning()
                || task.getState() == TaskState.WAITING) {
            synchronized (task) {
                task.wait(100);
            }
        }
        task.removeTaskListener(taskTerminationWaiter);

    }

    public  TaskManager();

}