Avoid doing a Thread.sleep() and instead do a wait and notify.