Search code examples
javamultithreadingcachingpool

Cache for reducing time of expensive object creations?


I have to use a legacy library that is in some parts very expensive on object creation (just "plain" objects, no database connection or likewise). As I'm writing a webservice with it, there will be many threads targeting the library.

The main problem will be the garbage collector having to clean up all the heavy objects of every thread.

Now I came around several cache pool approaches. But I have no experience in this. Could you recommend what cache pool library is most suitable if object creation is very expensive?

  • Guava
  • Apache Commons
  • or own implementation?

Solution

  • Object creation isn't what it used to be -- it is much more efficient. In most cases with modern JVMs, you are better off not worrying about it. Don't introduce the complexity and maintenance overhead of creating your own caching code unless you are sure you really need to -- and you can't be sure until you get some performance metrics via testing.