Arrange wait and notify methods

  • 16
  • Locked
Arrange wait and notify methods. Example output: Thread-0 MailServer received: [Person [Thread-1] wrote an email 'AAA'] in 1001 ms.
You can't complete this task, because you're not signed in.
Comments (1)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Justin Smith
Level 38 , Greenfield, USA, United States
7 April 2022, 15:08
I found this one pretty difficult, even though it's not a lot of work, just in terms of understanding how the code is meant to execute, which isn't really spelled out clearly in the conditions. What it should do is make sure that the run() method for the MailServer object waits until the mail object has text in it, and it's the responsibility of the Person object to let the MailServer object know when that happens. The most important learning component of this task, IMO, is the difference between wait(int n) and wait(). We have had other tasks that use wait(1) inside the synchronized block, and so my initial instinct was to do that here. But the goal here is to wait until notification. That's what wait() does. It causes it to listen for notify(). Good task for learning.