You don't see "wait" because your guide is free by default.
!isGuide && !isInShop
returns true while you only print when!isFree()
.You should call
lockObject.notifyAll()
. A direct call tonotifyAll()
by default invoke on this object and you certainly didn't hold the monitor of the anoymous object implementing Runnable interface because you never did by callingsynchroized(this)
. That's why you got the exception.Yes. You should use an
Executor
e.g.SingleThreadExecutor
together with a concurrent queue. That's the robust and easy way to implement concurrency unless you goes on high performance computing. That package also provide excellent functinoalities and supporting utilitiy classes. Check outjava.util.concurrent
.
BTW, your package name contains Upper letter which isn't recommended by java programming specification.