Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java - calling synchronized method from inside synchronized while waiting

Tags:

java

is it possible to call a synchronized method from inside a synchronized method while waiting for resource to become available (using wait())? thanks

like image 894
jkl Avatar asked Jan 22 '23 08:01

jkl


1 Answers

Java's mutexes are recursive, so you can invoke a synchronized method recursively or invoke another synchronized method for which you already hold a lock. You will need to tell us what it is you are specifically trying to do, though.... lots of stuff with thread locking/synchronization, if done incorrectly, can lead to deadlock, and it isn't entirely clear from your question what you are attempting to do.

like image 189
Michael Aaron Safyan Avatar answered Mar 22 '23 22:03

Michael Aaron Safyan