When I was taking a interview of Java developers and talking to my colleagues, In almost all the cases I was asking a simple trivial question "What is synchronization?". Surprisingly I haven't seen this question answered 100%. The gist of all the answers is synchronization is required for stop two threads running concurrently some code (mutual exclusion).
Is synchronization just a mutual exclusion. Certainly not. There is more to Synchronization than just mutual exclusion. Synchronization ensures that memory writes by a thread before or during a synchronized block are made visible in a predictable manner to other threads which synchronize on the same monitor. After we exit a synchronized block, we release the monitor, which has the effect of flushing the cache to main memory, so that writes made by this thread can be visible to other threads. Before we can enter a synchronized block, we acquire the monitor, which has the effect of invalidating the local processor cache so that variables will be reloaded from main memory. We will then be able to see all of the writes made visible by the previous release. There is some ugly truth that compiler or cache can reorder the non synchronized code with few exceptions of volatile. Keep watching I will write another blog on it as well.
Source of information: http://www.cs.umd.edu/~pugh/java/memoryModel/jsr-133-faq.html
Many software companies in the United States and Western Europe prefer outsourcing to Eastern Europe. But what are the pros and cons of this region over other outsourcing destinations? Here's everything you need to know about software development in Eastern Europe
ReplyDeletei never know the use of adobe shadow until i saw this post. thank you for this! this is very helpful. is best in singapore
ReplyDelete