Just wanted to check to make sure that I understand this. A synchronized method doesn't create a thread, right? It only makes sure that no other thread is invoking this method while one thread within the same process (ie the JVM) is using it, right?
A synchronized method doesn't create a thread, right?
Right.
It only makes sure that no other thread is invoking this method while one thread within the same process (ie the JVM) is using it, right?
Right.
For more information, read Synchronized Methods. I also recommend reading Java Concurrency in Practice.
That's mostly correct. Calling a synchronized method does not spawn a new thread. It just makes other threads block when they try to call any other synchronized method for that instance of that object.
The key thing to remember is that all synchronized methods of a class use the same lock.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With