|
Replies:
7
-
Last Post:
Nov 1, 2008 3:11 PM
by: dikasths
|
|
|
|
|
|
|
How to load in properties just once in J2EE?
Posted:
Oct 31, 2008 3:09 AM
|
|
|
Hi
I am loading in some information which only should be loaded once and hereafter resused across many stateless session calls.
How do I do that in J2EE without using the keyword static and the use of Singletons?
/ Kasper
|
|
|
|
|
|
|
Re: How to load in properties just once in J2EE?
Posted:
Oct 31, 2008 8:26 AM
in response to: mollekas
|
|
|
Why wouldn't you want to use static or a singleton?
|
|
|
|
|
|
|
|
Re: How to load in properties just once in J2EE?
Posted:
Oct 31, 2008 9:20 AM
in response to: jester9114
|
|
|
I thought the usage of the static keyword and Singletons was bad when using clustering.
So what do you do in the J2EE world when you want to simulate a singleton?
|
|
|
|
|
|
|
|
Re: How to load in properties just once in J2EE?
Posted:
Oct 31, 2008 9:46 AM
in response to: mollekas
|
 |
Helpful |
|
|
You are correct about singletons, static and clustering.
I would use a database or a distributed cache(i.e. ehcache) to accomplish loading once and sharing across many instances.
You may want to read this article if you don't want to use either one of those possible solutions. http://www.roseindia.net/javatutorials/J2EE_singleton_pattern.shtml
Someone please correct me if I am wrong or has a better solution.
|
|
|
|
|
|
|
|
Re: How to load in properties just once in J2EE?
Posted:
Oct 31, 2008 2:47 PM
in response to: jester9114
|
|
|
you can use a servlet to load the properties on startup of the application.
use the load-on-startup tag in the web.xml to prioritize the servlet if you have dependencies on other initialization servlets.
|
|
|
|
|
|
|
|
Re: How to load in properties just once in J2EE?
Posted:
Nov 1, 2008 7:16 AM
in response to: jester9114
|
 |
Helpful |
|
|
The problem with static, singletons, and clusters are only important if you're using them to maintain any kind of dynamic data.
If you properties are truly static (i.e. load once at startup), and the same across instances (or, at least instance centric), then statics and singletons won't be a problem within a cluster. Each instance will have the appropriate "world view" as seen through the singleton.
If you plan on updating the information without restarting the server, then you'd need some kind of cluster wide caching solution. But if restarting the server is acceptable for property value changes, there's no real reason for all that complexity.
|
|
|
|
|
|
|
|
Re: How to load in properties just once in J2EE?
Posted:
Nov 1, 2008 9:52 AM
in response to: whartung
|
|
|
> The problem with static, singletons, and clusters are > only important if you're using them to maintain any > kind of dynamic data. > > If you properties are truly static (i.e. load once at > startup), and the same across instances (or, at least > instance centric), then statics and singletons won't > be a problem within a cluster. Each instance will > have the appropriate "world view" as seen through the > singleton. > > If you plan on updating the information without > restarting the server, then you'd need some kind of > cluster wide caching solution. But if restarting the > server is acceptable for property value changes, > there's no real reason for all that complexity.
This was just what I thought ... but I hoped that there were some standard way through Glassfish/J2EE to handle this issue .... is it first from EJB 3.1 that there are some standard to handle this issue through cluster aware singletons?
/ Kasper
|
|
|
|
|
|
|
|
Re: How to load in properties just once in J2EE?
Posted:
Nov 1, 2008 3:11 PM
in response to: mollekas
|
|
|
You can use a simple java class with the properties initialized using spring
|
|
|
|
|