Synchronization
Hi,
Please can anyone tell me when to use synchronization and when not to use with program samples?.
Thanks...
Babu Shanmugham
Hi,
Please can anyone tell me when to use synchronization and when not to use with program samples?.
Thanks...
Babu Shanmugham
for example if u have list that is used by multiple threads... so when ever u have to access that list (change or read) you have to do that in synchronized block..
synchronized (list) {
list.add("...");
}
So, it means when multiple threads are accessing a resource then you have to do synchronization to prevent ConcurrentModificationException and other concurrency problems that u do not want to face...
but synchronization gives birth to deadlock... to solve that, read about monitors... wait(), notify(), notifyAll()....
Yes synchronization may come with other problems if not carefully implemented.. so it should be studied carefully before implementing