I have some questions regarding the usage and significance of the synchronized
keyword.
synchronized
synchronized
means that in a multi threaded environment, an object having synchronized
method(s)/block(s) does not let two threads to access the synchronized
method(s)/block(s) of code at the same time. This means that one thread can't read while another thread updates it.
The second thread will instead wait until the first thread completes its execution. The overhead is speed, but the advantage is guaranteed consistency of data.
If your application is single threaded though, synchronized
blocks does not provide benefits.