Brian Goetz Tech Talk

April 2, 2008


One of many great things when working at Sun is you get to meet some of the smartest people in the industry, and Brian Goetz is one of them. Brian Goetz is the author of Java Concurrency in Practice, a must read for anyone who programs in Java and has to deal with threads, locks, memory, performance, and the likes at some point.

Mr. Goetz is the speaker at our Brown Bag TechTalk this week, and the topic is one of my favorite, “Java Performance Myths”.  You probably heard a lot of myths regarding Java, some are true, some were true at one point of time, some are just flatly false. 

Some common myths are:

  • Java is slow
  • Garbage-collection is slow
  • Synchronization is slow
  • Object allocation is slow
  • Making methods “final” makes them faster

During the session, Mr. Goetz went over some of these myths, commented on their origins, and how these myths are no more myths thanks to some major improvements made to the modern JVM. For example, garbage-collection was made orders of magnitude faster by switching to generation-partitioned heap. Synchronization cost was reduced by JVM through the uses of adaptive locking, lock coalescing, lock elision, etc.  See the References section for more details.

The take home lessons from the session? Don’t try to outsmart the JVM. Small performance tricks are not worth the effort. Important to make your code clean and functionality correct first, ie.,  the classic Double-checked locking scheme.  JVM optimization will do the rest for you, most of the time.

With multi-cored CPUs a standard on modern day hardwares, it is especially important to utilize the concurrent capability of Java programming language to scale you application when it has more processing power.  But Java concurrency can be tricky to even the experts, and the pitfalls are difficult to reproduce, and they can be hidden in your code for a long time before they crash your application at mission critical time.

You can get a better understanding of Java concurrency by reading Brian Goetz’s book on Java Concurrency in Practice, I found it very useful and real enlightenment to read it from cover to cover.

References: