If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

J2EE Caching

Bjarki,

Welcome! I have a question regarding J2EE caching. Let's suppose I have
a data structure, somewhat complex and time-consuming to build, not persisted
in a RDBMS, that I would like to cache and expose to my EJB's. What is the
best way to accomplish this?

Some gotcha's here:
1)Because of the nature of the data structure we want to cache (memory/perf
intensive to build) it does not make a good candidate for an EJB itself,
because we do not want our EJB container creating multiple instances of this
structure.
2) Because this data structure is essentially a Singleton, how do we expose
a single-instance of this data structure to the EJB's in a *non app-server
specific* (i.e. portable manner)?

Re: J2EE Caching

Bjarki,

Related to this Question. I have a Controller Facade that talks to 19 other
BMP entity Beans. Whats is the best way to handle caching each of these beans
Interfaces so I don't have to keep finding by primary key or getting the
home each time. Intereset to hear you approach to this.

Re: J2EE Caching

Hello Brad!

A proper solution to this problem will always depend on the scale and nature
of the system in question. But I have actually been dealing with a similar
problem myself recently, so I will discuss below how I solved that, for my
particular system.

In my setup, I had a cluster of servers, each running HTTP and application
servers. HTTP requests were directed to a specific server by means of a load
balancing mechanism in front of the "middle tier".

Similar to your problem, I had to access a particular data object from each
application server. This data object was designed to be a Singleton, so the
problem was how I should share the instance between different application
servers.

As a solution, I invented for each application server an event manager, that
listened after all Events that were fired for the application. When the Singleton
data object was modified on a particular server (no chance to know which
one, since the application was load-balanced), an object-modified-event was
fired, and caught by the event manager. The event manager would contact all
the other event managers through a message-driven EJB bean (if you are not
using an EJB 2.0 compliant bean container, you could simply use JMS or even
RMI). When an event manager was contacted by another event manager, he would
take appropriate action on the local data object instance, thus ensuring
integrity and portability for the whole system.

I hope you understand what I'm getting at here. Of course, there are probably
many other solutions to this problem, some of which might be more appropriate
in your situation.

Re: J2EE Caching

Robert,

I'm sorry I haven't got back to you earlier

If I'm not misunderstanding, I would think that your facade implementation
should be able to store these references in some type of collection object.
How is the facade set up? Are you performing in a clustered environment?

Please give me some more details, so that I can better visualize the scenerio.