> Can anyone explain this behaviour? It is basically the minimum amount
> of code to set up a thread that waits until it is notified by the main
> thread.
Where did you get that code from?
> In this code the notify does not work because of the way it uses an
> instance of the Outer class to specify the Runnable passed to the
> Thread constructor.
> However, if the first two lines of the test method are replaced by:
> Thread t = new Thread(new Worker());
> it works as expected.
With the out.new Worker() version you are using a different Outer and
hence lock object for the wait than for the notify. The new Worker()
version, with implicit this., uses the same object for both wait and notify.
> public class Outer {
> private Object lock = new Object();
[quoted text clipped - 19 lines]
> }
> }
Tom Hawtin

Signature
Unemployed English Java programmer
http://jroller.com/page/tackline/
> Hi,
> Can anyone explain this behaviour? It is basically the minimum amount
[quoted text clipped - 28 lines]
> lock.notifyAll();
> }
You synchronize and notify on the wrong lock object (not the same as
used in your wait). When you change the above 3 line to
synchronized(out.lock) {
out.lock.notifyAll();
}
it will work again.
> }
> }

Signature
"Thomas:Fritsch$ops:de".replace(':','.').replace('$','@')