It is not mandatory to call wait and notify in a loop, it can be called in different synchronized method.
to prevent doing task, if condition is not true and thread is awake due to false alarms, checking conditions in loop ensures that processing is only done when business logic allows.