Fix an test error by awaiting the thread termination using ExecutorService