-
Global variables in EJB3 (6 messages)
- Posted by: Jerdno Truh
- Posted on: December 06 2006 13:07 EST
Our server has to cache various kinds of data with quite complex structure. We can't simply read the data from database for each request because performance would be unacceptable. We need to store the data somewhere in memory to have fast access to it. We could use global variables (static class fields) in J2SE Java but that seems to be forbidden for JEE code. For now we just ignored this restriction and our server code running in JBoss successfuly uses static class fields to store global data. We never had problems during development but we never run the code in serious production environment. Can static class fields really cause trouble and why ? Is there any other *portable* means to keep global variables ? We could use JBoss cache but we don't want to bind ourselves to JBoss.Threaded Messages (6)
- Re: Global variables in EJB3 by Farzad Kohantorabi on December 06 2006 21:54 EST
- Re: Global variables in EJB3 by Erik Putrycz on December 07 2006 11:06 EST
-
Re: Global variables in EJB3 by Manoj Sahu on December 08 2006 12:18 EST
- Not cool by Lorenzo Gonzalez on December 10 2006 03:17 EST
-
Re: Global variables in EJB3 by Manoj Sahu on December 08 2006 12:18 EST
- Re: Global variables in EJB3 by Erik Putrycz on December 07 2006 11:06 EST
- Re: Global variables in EJB3 by AMulya Mishra on December 06 2006 23:59 EST
- clustered versus not by Cameron Purdy on December 20 2006 09:13 EST
-
Re: Global variables in EJB3[ Go to top ]
- Posted by: Farzad Kohantorabi
- Posted on: December 06 2006 21:54 EST
- in response to Jerdno Truh
JBoss Cache runs in any JEE application server. -
Re: Global variables in EJB3[ Go to top ]
- Posted by: Erik Putrycz
- Posted on: December 07 2006 11:06 EST
- in response to Farzad Kohantorabi
The underlying technology should handle transparently all the caching. I don't know well EJB3 but with Hibernate, you can completly configure that cache and specify what kind of policy you want for each type of object. And when correctly configured, accessing twice the same object doesn't necessarily reload it from the database. IMO when you need to implement your own caching in a J2EE server, it means that something is wrong in your software stack/configuration. Anytime soon you might hit another cache/scaling issue. -
Re: Global variables in EJB3[ Go to top ]
- Posted by: Manoj Sahu
- Posted on: December 08 2006 12:18 EST
- in response to Erik Putrycz
One of the possibility could be to use a ThreadLocal variable. -
Not cool[ Go to top ]
- Posted by: Lorenzo Gonzalez
- Posted on: December 10 2006 15:17 EST
- in response to Manoj Sahu
I'm using ThreadLocal but it is not a cool API. Are there any problems for using that? -
Re: Global variables in EJB3[ Go to top ]
- Posted by: AMulya Mishra
- Posted on: December 06 2006 23:59 EST
- in response to Jerdno Truh
I would have gone for multiple read-only Entity Beans and set the variables and their values which need to be cached. Ensure, only one instance of the Bean for your global variables exists in the memory. -
clustered versus not[ Go to top ]
- Posted by: Cameron Purdy
- Posted on: December 20 2006 09:13 EST
- in response to Jerdno Truh
Static fields are only a problem on redeployment or when clustering. If not hot redeploying or clustering, static is OK. If hot redeploying, then static must be on a class in the classpath (not part of the hot redeploy) and the type of the object stored in the static (and everything it references) must also be in the classpath. If clustering, use Tangosol Coherence as a data grid. Peace, Cameron Purdy Tangosol Coherence: The Java Data Grid