To deal with the IllegalMonitorStateException
: You cannot call wait
or notify
on an unsynchronized object. You must synchronize on the object you wish to call wait
or notify
on.
But I think your code has other issues, for example, if you wait
on trader
, you'll want to notify
on trader
. And, I suspect there are even more issues, but I'll restrict my answer to addressing the OPs direct question.