Thread synchronization and happens-before relation in simple examples
Your code here is pretty mixed up and is not representative of a decent test of concurrency. It will work and give you the results you expect, but the reason is a bit polluted.

The internal code for System.out.println() looks like:

public void println(String x) {
    synchronized (this) {
        print(x);
        newLine();
    }
}


As a result, there are many more synchronizations than you expect. These are nested inside another synchronization block.

In essense, any time there is a println() you have a possibly conflicting synchronization problem.

In this case, it does not make much of a difference, but your code concerns me.

Additionally, it is traditional to incorporate the wait-conditions in the while-loop, and not as a break condition. Your code:


   synchronized (object) {
        while(true) {
            try {
                object.wait();
            } catch (InterruptedException e) {
                System.out.println("Interrupted!");
            }

            System.out.println("Notified!");

            if(result1 != null &amp;&amp; result2 != null) {
                System.out.println(result1 + " " + result2);
                break;
            } else {
                System.out.println("Not ready");
            }
        }
    }



Would be better as:

   synchronized (object) {
        while(result1 == null &amp;&amp; result2 == null) {
            object.wait();
        }
    }
    System.out.println(result1 + " " + result2);


Note that I have stripped out your InterruptException handling. It was not sufficient for "real" code, and if you replace it, should probably go outside the calls. If someone interrupts your code, continuing in a loop is probably not the right thing to do.