question on Thread synchronization
Answers were Sorted based on User's Feedback
Answer / 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 |
Answer / dayanand pujer (from gokak)
Threads commonly share the same memory space area, that’s
why they can share the resources. Threads commonly
communicate by sharing access to fields and the objects
reference fields refer to. This communication type is
extremely efficient, but makes two kinds of problems: thread
interference and memory consistency errors. By the
synchronization tool we can avoid this problem. In other
words, There is very critical situation where we want only
one thread at a time has to access a shared resources. For
example, suppose two people each have a checkbook for a
single account same as like two different threads are
accessing the same account data.
| Is This Answer Correct ? | 3 Yes | 0 No |
5 Coding best practices you learned in java?
Can we override constructors in java?
Explain yield() method in thread class ?
Why only one Class is public in one file? Explain in details. Thanks in Advance.
which one is more efficient int x; 1. if(x==null) 2.if(null==x) state which one either 1 or 2?
Give the difference between the println method and sqrt method?
How will you call an Applet using Java Script Function?
What is the differences between heap and stack memory in java? Explain
What are the interfaces defined by Java.lang package?
Explain the difference between getAppletInfo and getParameterInfo?
What is the java project architecture?
What is array class in java?