Showing posts with label cache. Show all posts
Showing posts with label cache. Show all posts

Friday, January 18, 2008

Writing Cluster Application

Here is a checklist of things that need to be done to write good application which would work in Cluster enviroemnt

  • When accessing the cluster from outside using HTTP or RMI verify that access to the cluster is done throught load balancer, this can be either software or hardware load balancer.
  • Consider using 'Optimistic Locking' or 'Pemisitic Locking' if two or more clients may update the same row in the databse at the same time
  • If you want to cache data all over the cluster and not on a single server then don't use Singleton, you would need to user Cache framework such as GigaSpaces or OSCacheor JCache etc', this solution is good mainly for read only data or data which is mostly read.
  • In many application servers you can configure your MDB if it would run on a single server or on several servers.
  • Avoid reading files/writing to files in the code, Since you may run on different hosts in the cluster and the files may not exists on the current host which you are running
  • Use Synchronize where two threads may access the same data at the same time, This problem can also occure on non cluster system.

Please comment if you have other issues which are missing.

Monday, December 10, 2007

Resource Bundle Surprise

Not many people knows but Resource Bundle which used to read properties files actually cache the property file content in memory, those changing the content of the properties file at run time wouldn't influence on the application.

The question is how to cause the application to reload the properties file without the need to restart the application server?

The answer is a bit tricky since the resource bundle doesn't expose an API to refresh the cache of the properties file, there is a need to write an MBean which would invoke by the JMX console and this MBean would refresh the properties file content, here is the code for that:

Class aClass = ResourceBundle.getBundle(PROPERTIES_FILE).getClass().getSuperclass();
Field field = aClass.getDeclaredField("cacheList");
field.setAccessible(true);
sun.misc.SoftCache cache = (sun.misc.SoftCache) field.get(null);
cache.clear();


First we get the class of the resource bundle, then we change the cacheList field from private to public (Yes it is possible to change using reflection private memebers to public members) and then get invoke clear method on the cache field.

Links

 
RSS Feeds Submission Directory