Answer Posted / rajani nagandla
With respect to multithreading, 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 a particular 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 which
may otherwise lead to dirty reads and significant errors.
E.g. synchronizing a function:
public synchronized void Method1 () {
// method code.
}
E.g. synchronizing a block of code inside a function:
public Method2 (){
synchronized (this) {
// synchronized code here.
}
}
| Is This Answer Correct ? | 10 Yes | 3 No |
Post New Answer View All Answers
I want to control database connections in my program and want that only one thread should be able to make database connection at a time. How can I implement this logic?
What is getclass () getname () in java?
What is heterogeneous in java?
How do you clear a list in java?
What is unmodifiable list in java?
What state does a thread enter when it terminates its processing in java programming?
What is java dot?
how its run?
What are the differences between checked exception and unchecked exception?
Can this keyword be used to refer static members?
What is internal iteration in java se 8?
What is the purpose of javac exe?
What are the five major types of reference sources?
Explain about join() method?
What is nextint java?