Handle InterruptedException for wait() and sleep()