The Source for Java Technology Collaboration

Home » java.net Forums » GlassFish » GlassFish

Thread: How to load in properties just once in J2EE?

Welcome, Guest Help
Login Login
Guest Settings Guest Settings
This question is not answered. Helpful answers available: 0. Correct answers available: 1.

Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 7 - Last Post: Nov 1, 2008 3:11 PM by: dikasths
mollekas

Posts: 4
How to load in properties just once in J2EE?
Posted: Oct 31, 2008 3:09 AM
 
  Click to reply to this thread Reply

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

jester9114

Posts: 2
Re: How to load in properties just once in J2EE?
Posted: Oct 31, 2008 8:26 AM   in response to: mollekas
 
  Click to reply to this thread Reply

Why wouldn't you want to use static or a singleton?

mollekas

Posts: 4
Re: How to load in properties just once in J2EE?
Posted: Oct 31, 2008 9:20 AM   in response to: jester9114
 
  Click to reply to this thread Reply

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?

jester9114

Posts: 2
Re: How to load in properties just once in J2EE?
Posted: Oct 31, 2008 9:46 AM   in response to: mollekas
Helpful
  Click to reply to this thread Reply

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.

jayasimhan

Posts: 1
Re: How to load in properties just once in J2EE?
Posted: Oct 31, 2008 2:47 PM   in response to: jester9114
 
  Click to reply to this thread Reply

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.

whartung

Posts: 634
Re: How to load in properties just once in J2EE?
Posted: Nov 1, 2008 7:16 AM   in response to: jester9114
Helpful
  Click to reply to this thread Reply

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.

mollekas

Posts: 4
Re: How to load in properties just once in J2EE?
Posted: Nov 1, 2008 9:52 AM   in response to: whartung
 
  Click to reply to this thread Reply

> 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

dikasths

Posts: 1
Re: How to load in properties just once in J2EE?
Posted: Nov 1, 2008 3:11 PM   in response to: mollekas
 
  Click to reply to this thread Reply

You can use a simple java class with the properties initialized using spring




 XML java.net RSS