If the main thread gets to run first, and starts waiting - it's waiting within the synchronized(args){} block. How will the thread AnotherThread manage to enter it's synchronized(args){} block in order to sort the array? Isn't the idea of the synchronized(args){} block that no 2 threads can be in a synchronized(args){} block at the same time - because args is the same array => they're using the same lock.... => if the main thread manages to go into it's synchronized(args){} block first, the program should stall on main thread's wait() because the thread AnotherThread will not be able to enter its own synchronized(args){} block because it doesn't have the lock for it....If the main thread gets to run first, it will enter the synchronized block and will start waiting. Now, AnotherThread will run, sort the list and call notifyAll(), thereby awaking the main thread. The main thread will dump the contents of the args array. And the program will terminate.
Please explain...
Thanks