wood burning stoves 2.0*
The moose likes EJB and other Java EE Technologies and the fly likes Caching objects in EJB and threading Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Caching objects in EJB and threading" Watch "Caching objects in EJB and threading" New topic

Caching objects in EJB and threading

Justin Chu
Ranch Hand

Joined: Apr 19, 2002
Posts: 209
What's a correct way to maintain a cache of objects queried from the database and make it available to remote clients through a SLSB?

Seems like it is very difficult to achieve this without violating EJB rules against managing threads and static variables (or by using singleton). In order to have objects shared by threads, they have to be stored in some static scope, and synchronization is a must.
[ December 10, 2008: Message edited by: Justin Chu ]
Reza Rahman
Ranch Hand

Joined: Feb 01, 2005
Posts: 580

If you are using EJB 2.x, entity beans will do that for you, if you can stomach the complex development model. If you are using EJB 3.0, the way to do this would be through second-level caching. In Hibernate nomenclature, this is called an L2 cache: http://www.devx.com/dbzone/Article/29685. TopLink/EclipseLink has similar capabilities: http://wiki.tangosol.com/display/COH33UG/Using+Coherence+and+TopLink+Essentials. You can also always use Hibernate or JPA with EJB 2.x (very common scenario).


Independent Consultant — Author, EJB 3 in Action — Expert Group Member, Java EE 6 and EJB 3.1
I agree. Here's the link: http://aspose.com/file-tools
subject: Caching objects in EJB and threading
Similar Threads
Theards synchronization and Static keyword
synchronization for static methods
concurrent access of session ejbs
Synchronizing question
Static threads - do they exist?