ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "De Gaetano Giuseppe" <degaet...@PITAGORA.IT>
Subject SqlMapClient multithread applications
Date Fri, 05 Jan 2007 13:23:16 GMT
Hi, 

I am coding a java multithread application.

In my application I have the following object which needs to load the
configuration files from a path not specified in the classpath end build
an SqlMapClient.

The Hashtable is used for:

*         cache the clients and avoid the building of a new SqlMapClient
every time;

*         speed up the application avoiding to load and parse the
different config files every time

 

public class SqlMapClientConfig {

    private static Hashtable clients;

    

    static{

            clients = new Hashtable();

    }

    

    private SqlMapClientConfig(){

        

    }

    

    public Object clone() throws CloneNotSupportedException {

        throw new CloneNotSupportedException();

    }

    

    

    public static SqlMapClient getClient(String db, String usecase,) {

        String key =  db + "." + usecase;

        String path = "/dat/" + db + "/" + usecase;

        

        

        if(clients.containsKey(key))

            return (SqlMapClient) clients.get(key);

        else{

            Loader loader = new Loader(path);

            Resources.setDefaultClassLoader(loader);

            Reader reader = null;

        try {

             reader = Resources.getResourceAsReader (loader,
"sql-map-config.xml");

         } catch (IOException e) {

             e.printStackTrace();

         }

         SqlMapClient sqlMap = null;

                  

         sqlMap = (SqlMapClient)
SqlMapClientBuilder.buildSqlMapClient(reader);

 

         clients.put(key,sqlMap);

         return sqlMap;

        }

    }

}

 

If the application is multithread and each thread uses the same client
will I have some problem?

Is the iBatis engine handling the concurrency or should I care?

 

Is there any best practice?

 

 

 


Mime
View raw message