Use awaitTermination() instead of while loop