I wrote this article for SitePoint’s Java channel, where you can find a lot of interesting articles about our programming language. Check it out!
synchronized keyword can be used to ensure that only one thread at a time executes a particular section of code.
This is a simple way to prevent race conditions, which occur when several threads change shared data at the same time in a way that leads to incorrect results.
synchronized either entire methods or selected blocks can be single-threaded.