How to use wait and notify in Java without IllegalMonitorStateException?

后端 未结 12 2311
后悔当初
后悔当初 2020-11-22 02:21

I have 2 matrices and I need to multiply them and then print the results of each cell. As soon as one cell is ready I need to print it, but for example I need to print the [

12条回答
  •  没有蜡笔的小新
    2020-11-22 03:26

    You can only call notify on objects where you own their monitor. So you need something like

    synchronized(threadObject)
    {
       threadObject.notify();
    }
    

提交回复
热议问题