I am really new to Java and I read that synchronized is \"very expensive\" in Java. All I want to know is what is expensive and how is it expensive?
Th
The other answers give a good level of technical detail that I'm not going to attempt to replicate.
What I will do is advise you to check the dates of the articles (as well as the implied competence and awareness of the author). Synchronization in Java was very slow in earlier JVMs. However, it's improved a lot recently, such that uncontended synchronization is a lot faster than you might think, and uncontended synchronization has improved too.
Mind you, this question possibly doesn't matter - if you need to synchronize to ensure correctness, you need to synchronize to ensure correctness. The only times I can see the speed being an issue is if you were considering creating a lockless implementation instead (using the very efficient yet complex java.util.concurrent.locks.AbstractQueuedSynchronizer), or perhaps considering using another language for your task instead.
In general I think the best conclusion is that synchronization is generally fast enough to use on a first iteration. As with all performance concerns, code for clarity and correctness at first and then only optimise what you measure to be an expensive part of your application. Typically, this won't be the cost of synchronization*.