How Synchronization impacts performance

  • Avoid synchronization where possible.
  • ArrayList is faster than Vector
  • Only List and Map have efficient thread-safe implementations: the Vector and Hashtable classes respectively.
  • Synchronized methods are slower than the identical non-synchronized one.
  • Consider using non-synchronized classes and synchronized-wrappers.
  • FastVector is faster than Vector by making the elementData field public, thus avoiding (synchronized) calls to elementAt().
  • Use threads. Prioritize threads. Use notify instead of notifyAll. Use synchronization sparingly.
  • use methods in order: static > final > instance > interface > synchronized
  • Because synchronization synchronizes thread memory with main memory, there is a cost to synchronization beyond simply acquiring a lock.
  • Make synchronized blocks as short as possible.
  • Spread synchronizations over more than one lock.
  • Minimizing synchronization may take work, but can pay off well.
  • Minimize the synchronized block in the service method.
Advertisements

One Response

  1. Wow! This blog looks exactly like my old one! It’s on a entirely different topic but it has pretty much the same layout and design. Outstanding choice of colors!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: