Forums Register Login

Synchronized Method or Code

+Pie Number of slices to send: Send
Methods call for the wait (), notify(), notifyall(), must be placed in side a synchronized block Is this always true ? Explain�

We can put these methods inside a non synchronized method or code without compile �time errors.
Can you explain the logic behind this?
+Pie Number of slices to send: Send
All those methods do need to be inside appropriate synchronisation. However, the lock could be obtained in some other piece of code, which then calls the method containing the wait(), notify() or whatever. Therefore, the compiler can't enforce this.
He's my best friend. Not yours. Mine. You can have this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 650 times.
Similar Threads
Syncronization
writeRecord
Thread,Lock,Object
Difference between synchronized method and synchrnoized block of code
Synchronized Block and Synchronized method
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 19, 2024 03:04:19.