dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: Enterprise
Expertise: Beginner
Jan 10, 2002

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


Control the Scope of a Singleton in an Application Server


Here is the code defining a singleton class:
 
public class SingletonClass{
 private static int id = 0;
 private static SingletonClass sclass = null;

 private SingletonClass(){}

 public SingletonClass getInstance(){
  if(sclass ==null )
    sclass = new SingletonClass  ();
  return sclass;
 }

 public void setID(int _id){
  id = _id
 }

 public void getID(){
  return _id
 }
}

You have two completely independent EJB's, EJBOne and EJBTwo These make use of the functionality of this SinlgetonClass. The requirement is that the ID set in EJBOne should not be accessible in EJBTwo.

You can do this by packing the SingletonClass in EJBOne.jar and EJBTwo.jar separately and then deploying them. Make sure that the SingletonClass in not in the classpath of the application server. Now the two EJB's will have a private SingletonClass instance available. If you put the SingletonClass in the application server classpath, then it will be shared by both the EJB's.
Ram Dhan
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date