Producer-consumer solution with wait() and notify() methods.