What do you understand by Synchronization?

By: Karthik Printer Friendly Format    


Answer: Synchronization is a process of controlling the access of shared resources by the multiple threads in such a manner that only one thread can access one resource at a time. In non synchronized multithreaded application, it is possible for one thread to modify a shared object while another thread is in the process of using or updating the object's value. Synchronization prevents such type of data corruption.

E.g. Synchronizing a function:
public synchronized void Method1 () {
     // Appropriate method-related code. 
}
E.g. Synchronizing a block of code inside a function:
public myFunction (){
    synchronized (this) { 
            // Synchronized code here.
         }
}



Ask a Question



Most Viewed Articles (in Interview )

What are all the different scope values for the tag?

Interview Question: Is there a particularly good IDE to use with Struts ?

Interview Question: How many EJB Objects are created for a Bean?

Interview Question: What is deployment descriptor?

What is transient variable?

How to define an Abstract class?

What is the difference between jsp:include page and @ include file?

What are implicit Objects available to the JSP Page?

Interview Question: What is Struts?

Interview Question: What is Struts Validator Framework?

Interview Question: Why does EJB needs two interfaces(Home and Remote Interface)?

Interview Question: Is Decorator an EJB design pattern?

Interview Question: What is lazy loading?

Interview Question: What is Message Driven Bean?

Interview Question: What is local interface. How values will be passed?

Latest Articles (in Interview)

Comment on this tutorial