[concurrency-interest] Implementation of a global configuration cache

Peter Veentjer alarmnummer at gmail.com
Mon Jun 15 05:08:09 EDT 2009


Hi Thejo,

would a COTS (common of the shelf) cache not be easier to use? It
saves you a lot of time compared to writing one yourself.

e.g.

ehcache.

On Mon, Jun 15, 2009 at 10:56 AM, Thejo Kote<thejo at kote.in> wrote:
> Hi,
>
> I'm trying to improve the design of a global configuration cache which
> currently consists of public static variables in a class. Something like -
>
> public final class ConfigCache {
>
>     public static String val1;
>     public static Map<Integer, MyObj> val2;
>
>     public static initializeCache() {
>         val1 = ....;
>     }
>
> }
>
> I use the config values in other parts of the applications as
> ConfigCache.val1 etc. The task performed by the application is highly
> parallelizable and many threads read the configuration values. Some config
> values don't change after initialization at start up and some (like val2)
> are periodically (every 15 minutes) read from a database and updated in the
> cache from a separate thread. I take advantage of the fact that writes to
> and reads of references are always atomic when updating cache values in run
> time.
>
> With that background -
>
> - Are the visibility characteristics of static and non-static variables the
> same? Is it just sheer luck that the reading threads pick up the last
> updated reference, and should they be declared as volatile?
> - I'm ensuring that no references escape by initializing the cache before
> the application accepts requests, but using public static fields is not
> ideal and does not provide the required encapsulation. Is there a standard
> pattern for implementing such a configuration cache where many threads
> constantly read values with an occasional write. Is a singleton object with
> proper use of read write locks on the values that keep changing the right
> solution?
>
> Thanks,
> Thejo
>
>
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest
>
>



More information about the Concurrency-interest mailing list