Here you can find the source of executeAndWait(final Runnable r)
public static void executeAndWait(final Runnable r)
//package com.java2s; //License from project: Apache License import java.util.concurrent.CountDownLatch; import java.util.concurrent.Executor; import java.util.concurrent.Executors; public class Main { private static Executor exec = Executors.newSingleThreadExecutor(); public static void executeAndWait(final Runnable r) { final CountDownLatch countDown = new CountDownLatch(1); Runnable task = new Runnable() { public void run() { try { r.run();// ww w .j av a2 s .c o m } finally { System.err.println("scheduled"); countDown.countDown(); } } }; exec.execute(task); try { countDown.await(); } catch (InterruptedException e) { e.printStackTrace(); return; } } }