Thursday, February 11, 2010

What is difference between Synchronized method and Synchronized block?

What is difference between Synchronized method and Synchronized block?


The key difference is this: if you declare a method to be synchronized, then the entire body of the method becomes synchronized; if you use the synchronized block, however, then you can surround just the "critical section" of the method in the synchronized block, while leaving the rest of the method out of the block.
If the entire method is part of the critical section, then there effectively is no difference. If that is not the case, then you should use a synchronized block around just the critical section. The more statements you have in a synchronized block, the less overall parallelism you get, so you want to keep those to the minimum.

What is difference between ArrayList and Vector ?

  1. The Vector class is synchronized, the ArrayList is not.
  2. ArrayList is fast than the Vector.




No comments:

Post a Comment