Hi gurus,
I have a little "phylosophical" question about using singletons from an
application which has EJBs. I'll tell you my problem and my purpose
solution:
-Problem: We want (in each computer if there is a cluster, so there
is no problem about this) an unique object (singleton). And we want to use
EJBs to build our application.
-Solution: Really, we can't use an EJB to implement the singleton
pattern (see http://www.jguru.com/jguru/faq/view.jsp?EID=37838), so our
singleton object must be implemented with "traditional" Java classes.
Singleton looks like this code (see "Design patterns",
Gamma/Helm/Johnson/Vlissides, Addsion Wesley)
public class MySingleton {
private static MySingleton instance;
public static Singleton getInstance() {
if(instance==null) instance = new MySingleton();
return instance;
}
// Non-static methods...
}
Now, from our EJBs, we access to this singleton through this code:
MySingleton the_instance =
MySingleton.getInstance();
the_instance.aMethod();
The question for you is: what do you think about this? Is it good/ is it
bad?
Do you think this implementation is not compliant with EJB 1.1
Specifications (which, in section 18.1.2 forbides the use of static fields
inside EJBs?
Which problems do you see?
TIA and regards.
Luis Canals
This message and any files transmitted with it are confidential and intended
solely for the use of the individual or entity to whom they are addressed.
No confidentiality or privilege is waived or lost by any wrong transmission.
If you have received this message in error, please immediately destroy it
and kindly notify the sender by reply email.
You must not, directly or indirectly, use, disclose, distribute, print, or
copy any part of this message if you are not the intended recipient.
Opinions, conclusions and other information in this message that do not
relate to the official business of Newknow shall be understood as neither
given nor endorsed by it.
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".