Goldman Sachs Interview Question
Software Engineer / DevelopersCountry: United States
Interview Type: Phone Interview
In Multithreaded environment where resources are shared between many threads we need some process to kepp system in consistent state, For that purpose we use synchronization.
In JVM we have monitors which work as Guardian to resources if a thread wants access to any resource (variable, method , etc..) which is shared it confirms that thread should lock the resource before using it , If no lock acquires then thread will wait for release of lock.
synchronization is used to prevent multiple threads accessing the shared object at the same time. This is to avoid any corruption of state of the object and any unexpected errors.
- Sr March 17, 2012