/** * Execute an arbitrary task on the executor of this resource or the first * parent that defines its own executor and wait until it the task is * completed. If no parent defines an executor, the thread that calls this * method executes the specified task. * * @param task the task * @throws InterruptedException the interrupted exception */ public void executeAndWait(final Runnable task) throws InterruptedException { final Semaphore semaphore = new Semaphore(0); execute(new Runnable() { public void run() { task.run(); semaphore.release(); } }); semaphore.acquire(); }
/** * Execute an arbitrary task on the executor of this resource or the first * parent that defines its own executor and wait until it the task is * completed. If no parent defines an executor, the thread that calls this * method executes the specified task. * * @param task the task * @throws InterruptedException the interrupted exception */ public void executeAndWait(final Runnable task) throws InterruptedException { final Semaphore semaphore = new Semaphore(0); execute(new Runnable() { public void run() { task.run(); semaphore.release(); } }); semaphore.acquire(); }