However I would like to think that the output could be unpredictable, here is my understanding it is also possible that the thread t1 might not get started immediately and hence the result could be ABC as everything is being set in class B or assuming that the new thread t1 does get started it gets into the run method and acquires the lock on the object as given by synchronized (sa) and it will be in the wait state as the main thread i.e (thread main) would not be able to obtain the lock sa as it has already been taken by t1 , Please correct me
If the main thread runs first, then ABC is set, and the notification actually get lost, because the t1 thread is not actually waiting. This is not a problem, since the t1 thread won't wait anyway -- because it checks the done flag first. Output is that ABC is printed.
If the t1 thread runs first, then the done flag is not set, and the t1 thread will call wait(), which also releases the lock. The main thread will block until the wait() method is called, since the lock is freed. It grabs the lock, set all the variables, and notifies the waiting threads. The t1 thread will return from wait() sometime after the main thread releases the sync lock, it checks the done flag again, and prints the results. Output is that ABC is printed.
Henry