I have a SLSB which returns data from a DB which is static between server start-ups. (lists of items for drop-down lists infact, although that isn't important)
At the moment these are cached in a non-final static member of my SLSB EJB class.
I know this is technically illegal according to the J2EE spec.
My questions are:
- when does doing it this way hurt?
- what's the right way to do it?
Thanks,
Tom
-
static caches in SLSBs (2 messages)
- Posted by: Tom Davies
- Posted on: August 25 2001 04:20 EDT
Threaded Messages (2)
- static caches in SLSBs by Toby Hede on August 26 2001 00:02 EDT
- static caches in SLSBs by Tom Davies on August 26 2001 02:23 EDT
-
static caches in SLSBs[ Go to top ]
- Posted by: Toby Hede
- Posted on: August 26 2001 00:02 EDT
- in response to Tom Davies
I don't think this is actually technically illegal at all. I don't have my spec in front of me, but I do remember that it allows for the caching of data like this in the Stateless Session Beans. As long as the data is not specific to particular instances of the bean, there should be no problems with storing such data for the lifetime of the EJB... -
static caches in SLSBs[ Go to top ]
- Posted by: Tom Davies
- Posted on: August 26 2001 02:23 EDT
- in response to Toby Hede
The text from the 2.0 spec is: (C.1.2)
"An enterprise Bean must not use read/write static fields. Using read-only static fields is allowed. Therefore, it is recommended that all static fields in the enterprise bean class be declared as final.
This rule is required to ensure consistent runtime semantics because while some EJB Containers may use a single JVM to execute all enterprise bean’s instances, others may distribute the instances across multiple JVMs."
So it seems to me that doing this is OK as long as I don't mind my cache being duplicated in seperate JVMs. (which I don't)
Are there other problems?
I would like to know what the 'sun-approved' way of caching data is.
Tom