Help the world stop coronavirus! Stay home!

Prev Next

Java / Java Multithreading part II

Which is faster?
(a) public void incrementI() {

synchronized (this) {
 i = i + 1;


(b) public synchronized void incrementI() {

 i = i + 1;


Option a is faster. Because option b, which is synchronizing on the method call has to run many instructions than option a which deals only with the critical section.

❤Cash Back At Stores you Love !!!❤

Earn your $10 reward when you make your first purchase through Ebates by signing up with clicking below button.

Ebates Coupons and Cash Back

More Related questions...

Show more question and Answers...

final keyword

Comments & Discussions