All,

I have a question regarding singleton DAO and multiple clients (threads) in IBATIS. If I use following codes, is thread safe if there are multiple clients (after I read mailing list, it gave me impression that sqlMapClient is thread safe)?. Is there any performance concern if I use singleton Service (DAO)?

Appreciate your inputs and suggestions.

Tony

Class MyService {
  private DaoManager daoManager;
  private Table1DAO table1Dao;
  private Table2DAO table2Dao;
  private static MyService myServiceInstance = null;

  private MemberService() {
    daoManager = DaoConfig.getDaoManager();
    table1Dao = (Table1DAO) daoManager.getDao(Table1DAO.class);
    table2Dao = (Table2DAO) daoManager.getDao(Table2DAO.class);
  }

  public static MyService getInstance() {
     synchronized(MyService.class) {
         if(myServiceInstance == null) {
             myServiceInstance = new MyService();
         }
      }
      return myServiceInstance;
  }

  public List getDataFromTable1(Integer someValue){
       try{
            Table1Example example = new Table1Example();
             example.setValue(someValue);
             example.setValue_Indicator( Table1Example.EXAMPLE_EQUALS)
             return table1Dao.selectByExample(example);
        }catche(Exception ex){
           // do something
        }
   }
 
 public void insertDataToTable1 (Table1 table1)
     try{
             table1Dao.insert(table1);
     }catch(Excpetion ex){
      }
}

Reply via email to