Hi,
Can I cache the instance of DAO in ejbCreate() ? I want to re-use the same instance of DAO across many ejbs.
Thanks
-
Design question : Caching DAO instance in ejbCreate() (7 messages)
- Posted by: ivory tower
- Posted on: April 06 2004 12:22 EDT
Threaded Messages (7)
- Design question : Caching DAO instance in ejbCreate() by Mircea Crisan on April 06 2004 13:01 EDT
- Design question : Caching DAO instance in ejbCreate() by Mircea Crisan on April 06 2004 13:03 EDT
-
Design question : Caching DAO instance in ejbCreate() by ivory tower on April 06 2004 04:13 EDT
- Design question : Caching DAO instance in ejbCreate() by balaji balakrishnan on April 07 2004 01:01 EDT
-
Design question : Caching DAO instance in ejbCreate() by Kumaraguruparan Karuppasamy on April 07 2004 05:50 EDT
- Design question : Caching DAO instance in ejbCreate() by ivory tower on April 08 2004 01:11 EDT
-
Design question : Caching DAO instance in ejbCreate() by ivory tower on April 06 2004 04:13 EDT
- Design question : Caching DAO instance in ejbCreate() by Mircea Crisan on April 06 2004 13:03 EDT
- Design question : Caching DAO instance in ejbCreate() by Andreas Berg on April 13 2004 15:27 EDT
-
Design question : Caching DAO instance in ejbCreate()[ Go to top ]
- Posted by: Mircea Crisan
- Posted on: April 06 2004 13:01 EDT
- in response to ivory tower
Hi,
As long as the DAO is thread safe I gues is ok.
Best regardds, Mircea -
Design question : Caching DAO instance in ejbCreate()[ Go to top ]
- Posted by: Mircea Crisan
- Posted on: April 06 2004 13:03 EDT
- in response to Mircea Crisan
Wrong .. don'ttake into account this .. I didn't know what I was thinking ... EJBs are thread safe by themselfs.Hi, As long as the DAO is thread safe I gues is ok.Best regardds, Mircea
-
Design question : Caching DAO instance in ejbCreate()[ Go to top ]
- Posted by: ivory tower
- Posted on: April 06 2004 16:13 EDT
- in response to Mircea Crisan
So, the simple answer is 'yes". We can cache the instance of DAO in ejbCreate(). -
Design question : Caching DAO instance in ejbCreate()[ Go to top ]
- Posted by: balaji balakrishnan
- Posted on: April 07 2004 01:01 EDT
- in response to ivory tower
Correct me if i am wrong. Most of the time the DAO is going to be stateless.if that is the case i don't see any advantage in caching the DAO instance. If it is going to be stateful, you might end up in data integrity problem unless you do some sophisticated data sync. For some reason if you would like to cache, make sure you are not holding any connection. -
Design question : Caching DAO instance in ejbCreate()[ Go to top ]
- Posted by: Kumaraguruparan Karuppasamy
- Posted on: April 07 2004 17:50 EDT
- in response to Mircea Crisan
What about static methods in the DAO? Are they thread safe too?
Thanks,
KK -
Design question : Caching DAO instance in ejbCreate()[ Go to top ]
- Posted by: ivory tower
- Posted on: April 08 2004 13:11 EDT
- in response to Kumaraguruparan Karuppasamy
By nature, the static methods are thread-safe so long as the usage is as per guidelines. -
Design question : Caching DAO instance in ejbCreate()[ Go to top ]
- Posted by: Andreas Berg
- Posted on: April 13 2004 15:27 EDT
- in response to ivory tower
Why do you want to use the same DAO instance? Is there anything you want to hold inside the DAO? Maybe the JDBC connection?
If yes, you can cache your DAO instances in ejbCreate - but I don't think it's a good idea. If you do so the lifetime of a connection is bound to the lifetime of the EJB. This is not the most efficient usage of database connections.
If you use a connection pool there is usually no need to cache connections somewhere else. The container will handle everything for you. There is no need to hold the connection inside the DAO, get it just before you want to make the JDBC call - and release it right afterwards.
Cheers,
Andreas Berg.
http://www.triona.de/