ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tony Qian" <daqiqi...@aol.com>
Subject Singleton DAO and mutilple threads
Date Wed, 25 Oct 2006 16:13:20 GMT
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <title></title>
</head>
<body>
<font size="2"><font face="Arial,sans-serif">All,<br>
<br>
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)?<br>
<br>
Appreciate your inputs and suggestions.<br>
<br>
Tony<br>
<br>
Class MyService {<br>
&nbsp; private DaoManager daoManager;<br>
&nbsp; private Table1DAO table1Dao;<br>
&nbsp; private Table2DAO table2Dao;<br>
&nbsp; private static MyService myServiceInstance = null;<br>
<br>
&nbsp; private MemberService() {<br>
&nbsp;&nbsp;&nbsp; daoManager = DaoConfig.getDaoManager();<br>
&nbsp;&nbsp;&nbsp; table1Dao = (Table1DAO) daoManager.getDao(Table1DAO.class);<br>
&nbsp;&nbsp;&nbsp; table2Dao = (Table2DAO) daoManager.getDao(Table2DAO.class);<br>
&nbsp; }<br>
<br>
&nbsp; public static MyService getInstance() {<br>
&nbsp;&nbsp;&nbsp;&nbsp; synchronized(MyService.class) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(myServiceInstance
== null) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
myServiceInstance = new MyService();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return myServiceInstance;<br>
&nbsp; }<br>
<br>
&nbsp; public List getDataFromTable1(Integer someValue){<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try{<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Table1Example example = new Table1Example();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
example.setValue(someValue);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
example.setValue_Indicator( Table1Example.EXAMPLE_EQUALS)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
return table1Dao.selectByExample(example);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }catche(Exception ex){<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
// do something<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp; }<br>
&nbsp;<br>
&nbsp;public void insertDataToTable1 (Table1 table1)<br>
&nbsp;&nbsp;&nbsp;&nbsp; try{<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
table1Dao.insert(table1);<br>
&nbsp;&nbsp;&nbsp;&nbsp; }catch(Excpetion ex){<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
}<br>
</font></font>
</body>
</html>


Mime
View raw message