Synchronization & Lock in Java Threads

Photo by Everton Vila on Unsplash

Threads share memory and resources (data, code etc.) Threads execute concurrently. Hence, threads can access common resources simultaneously. This may bring us some undesirable outcome.

Synchronization prevents threads from accessing common resources simultaneously. It allows a thread to access a resource at a time.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store