in Java recategorized by
5,996 views
1 vote
1 vote

Which methods are utilized to control the access to an object in multi-threaded programming ? 

  1. Asynchronized methods 
  2. Synchronized methods 
  3. Serialized methods
  4. None of the above 
in Java recategorized by
6.0k views

2 Answers

1 vote
1 vote

ans is B 

With respect to multi-threading, synchronization is the capability to control the access of multiple threads to shared resources. Without synchronization, it is possible for one Java thread to modify a shared variable while another thread is in the process of using or updating same shared variable. This usually leads to erroneous behavior or program.

1 vote
1 vote
answer is B

Synchronized methods enable a simple strategy for preventing thread interference and memory consistency errors. The following things can occur due to this:
1. If an object is visible to more than one thread, all reads or writes to that object's variables are done through synchronized methods.
2. It is not possible for two instances of synchronized methods on the same object to interleave. When one thread is executing a synchronized method for an object then other threads or methods block itself once the process of first thread execution is finished.
3. On the exit of synchronized method, it automatically creates a happens-before relationship with any other instance running of a synchronized method for the same object. This allow the changes to the state of the object that are visible to all threads.
Answer:

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true