开发者

A question on clustered environment on Weblogic server

开发者 https://www.devze.com 2023-01-25 18:03 出处:网络
I am using Weblogic 10g clustered environment to deploy my application.In my application, I have used a class Cache.java to load some properties from database lazily.This is how it works.Cache.java is

I am using Weblogic 10g clustered environment to deploy my application. In my application, I have used a class Cache.java to load some properties from database lazily. This is how it works. Cache.java is a singleton class with instance variables as cache objects. For example, one of the instance variables is List<String> STORES_IN_CITY. This cache is null when the clusters start. The actual values are in database. The implementation of the class is given below:

public class Cache
{
    private List<String> STORES_IN_CITY;

    private static final Cache cache=new Cache();

    public static Cache getCache()
    {
        return cache;
    {

    private Cache()
    {
        // private constructor to have singleton class
    }

    public List<String> getStoresInCity()
    {
        if(null==STORES_IN_CITY || STORES_IN_CITY.size()==0){
             STORES_IN_CITY=getStoresFromDatabase();
        }
        return STORES_IN_CITY;
    }
}

My question here is that there are multiple calls to database for getting the cache STORES_IN_CITY. I believe this is because of the 开发者_运维问答clustered environment, as for each server, there is a different JVM instance and a copy of cache. So depending on which server is hit for a request at runtime, the database call is made. I want to have a single cache across servers. Is this possible?

I hope the I have elaborated on my question enough. If any further explanation is needed, please let me know.

Thanks, Siddharth


(...) I believe this is because of the clustered environment, as for each server, there is a different JVM instance and a copy of cache.

This is correct.

I want to have a single cache across servers. Is this possible?

You could implement a weblogic.cluster.singleton.SingletonService (A singleton service is a service running on a managed server that is available on only one member of a cluster at a time).

Resources

  • Define a New Singleton Service
  • Configure a Singleton Service

Related question

  • WebLogic clustered singleton service
0

精彩评论

暂无评论...
验证码 换一张
取 消