Class AbstractCachingRuntimeRepository

  • All Implemented Interfaces:
    IRuntimeRepository
    Direct Known Subclasses:
    AbstractTocBasedRuntimeRepository

    public abstract class AbstractCachingRuntimeRepository
    extends AbstractRuntimeRepository
    This abstract runtime repository handles the caching for already loaded instances. The caching have to be thread safe for every cache instance that we do not load an object twice. That means, the regular way we load an object is to have a look in the cache if it is already there if not we call the getNotCached... method.

    To be performant and thread safe we use the double checking ideom as it is discribed by doug lea. Since we use Java 5 there is a threadsafe way to do so:
    First of all we have a not synchronized look in the cache. As we assume that the cache itself is implemented with a ConcurrentHashMap this lookup would see the real state of the map. If there is no object yet we have to enter a synchronized block. This block is synchronized for every cache instance so we could handle calls for different objects at same time. In this synchonized block it is important to check again if there is an cached object now because another thread may created one meantime (double-check). Again this only works for ConcurrentHashMap. If there still is no object cached we create a new one. As long we are in the synchronized block, every other thread is blocked. After the new object is created we put it in the cache and the ConcurrentHashMap ensures that it is stored completely initialized before another thread would get access.

    There is still potentially more performance by synchronizing for different keys instead of blocking for every cache instance. This would be more complicated and should be well-considered.

    Author:
    dirmeier
    • Constructor Detail

      • AbstractCachingRuntimeRepository

        public AbstractCachingRuntimeRepository​(java.lang.String name,
                                                ICacheFactory cacheFactory,
                                                java.lang.ClassLoader cl)