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 [
You have properly guarded your code block when you call wait()
method by using synchronized(this)
.
But you have not taken same precaution when you call notify()
method without using guarded block : synchronized(this)
or synchronized(someObject)
If you refer to oracle documentation page on Object class, which contains wait()
,notify()
, notifyAll()
methods, you can see below precaution in all these three methods
This method should only be called by a thread that is the owner of this object's monitor
Many things have been changed in last 7 years and let's have look into other alternatives to synchronized
in below SE questions:
Why use a ReentrantLock if one can use synchronized(this)?
Synchronization vs Lock
Avoid synchronized(this) in Java?