0 votes
1 view
in Java by (1.1k points)

I have some questions regarding the usage and significance of the synchronized keyword.

  • What is the significance of the synchronized keyword?
  • When should methods be synchronized?
  • What does it mean programmatically and logically?

1 Answer

0 votes
by (13.2k points)

When a resource is being shared by more than one thread, synchronization is needed which can be done by the keyword synchronized in java.

Take for example, a thread made a change to the shared data and another thread wants to now access this data, the data that his resource will get should contain all the changes made by the previous thread.To avoid anonymity and confusion coordination of events it is needed so that the threads are in unison.

// Only one thread can execute at a time. 

// sync_object is a reference to an object

// whose lock associates with the monitor

// The code is said to be synchronized on

// the monitor object

synchronized(sync_object)

{

   // Access shared variables and other

   // shared resources

}

Related questions

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...