Use of wait and notify rather than loop while and sleep.