Concerns about Singleton classes in EAR archive

Let's say I have an EAR file with the following structure:
employee.jar<br>
employeeSearchEJB.jar<br>
webApp1.war<br>
webApp2.war<br>
META-INF<br>
application.xml<br>
If there is a singleton class in the employee.jar utility archive, then does there
exist a single instance of that singleton class for each web application in
the EAR? I hope not because that would seriously screw things up with me. I would
be upset, to say the least.
SAF

I tested it out, and you're right, only 1 instance of the singleton exists at the
EAR level.
Thanks,
SAF
"mike iwaskow" <[email protected]> wrote:
>
If there is a singleton class in the employee.jar utility
archive, then does there exist a single instance of that
singleton class for each web application in
the EAR ?
Based on your scenario, I believe the answer is "No".
I'm knowledgeable with WLS 5.1 and up, not 4.51.
Your best bet is to give it a try. If a problem does occur,
contact BEA support at [email protected]
Developer Relations
BEA Support

Similar Messages

  • To ragnic and other about Singleton class

    Hi ragnic. Thanks for your reply. I posted the code wrong. Heres' my correct one.
    I have a GUI first loaded information and the information is stored in a databse, I have some EJB classes..and my singleton class ABC has some method to access to the EJB..
    so my first GUI will gather info using singleton class and later if I click on
    a button in my first GUI class, will pop up another frame of another class , this class also need to class setPassword in my Singleton..
    are my followign codes correctly??
    iS my Class ABC a SINgleton class? thanks
    Is my class ABC use as single correctly. And It is called from other classes is also correct?
    I'm new to java and like to learn about Singleton class.
    But I really dont' understand it clearly after reading many examples of it.
    I have a project to convert my class abc to a singleton.
    But I dont know how to do it.
    In my class(soon will become a singleton) will have few methods that later I need to use it from another class A and class B.
    I have a GUI application that first load my class A..and my class will call
    class abc(singleton) to get some information from it.
    and then in class A has a button, if I click on that button I will call SIngleton class again to update my password, in the singleton class has method calls updatePassword. But I dont know how to call a singleton from other class.
    I have my code for them below:
    1)public class ABC //attempt using a singleton
    private static ABC theABC = null;
    private ABC(){}
    public synchronized static ABC getABC()
    if(theABC == null)
    theABC= new ABC();
    return the ABC;
    public void updateUserInfo(SimpleUser user)
    throws UserNotFoundException, DelegateException
    try
    UserCollectionHome userCollectionHome = (UserCollectionHome)
    EJBHomeFactory.getFactory().lookupHome("vista/UserCollection",
    UserCollectionHome.class);
    UserHome userHome = (UserHome)
    EJBHomeFactory.getFactory().lookupHome("vista/User",UserHome.class);
    UserCollection uc = userCollectionHome.create();
    uc.updateUserInfo(user, userHome);
    } catch(HomeFactoryException hfe) {
    hfe.printStackTrace();
    throw new DelegateException(hfe);
    } catch(RemoteException re) {
    re.printStackTrace();
    throw new DelegateException(re);
    } catch(CreateException ce) {
    ce.printStackTrace();
    throw new DelegateException(ce);
    } catch(FinderException fe) {
    fe.printStackTrace();
    throw new UserNotFoundException();
    public SimpleUser getID(String id)
    throws UserNotFoundException, DelegateException
    try
    UserCollectionHome userCollectionHome = (UserCollectionHome)
    EJBHomeFactory.getFactory().lookupHome("vista/UserCollection",
    UserCollectionHome.class);
    UserHome userHome = (UserHome)
    EJBHomeFactory.getFactory().lookupHome("vista/User",UserHome.class);
    UserCollection uc = userCollectionHome.create();
    SimpleUser su = uc.getID(id, userHome);
    return su;
    } catch(HomeFactoryException hfe) {
    throw new DelegateException(hfe);
    } catch(RemoteException re) {
    throw new DelegateException(re);
    } catch(CreateException ce) {
    throw new DelegateException(ce);
    } catch(FinderException fe) {
    throw new UserNotFoundException();
    public void setPassword(String lname,String pw)
    throws UserNotFoundException, DelegateException
    try
    UserCollectionHome userCollectionHome = (UserCollectionHome)
    EJBHomeFactory.getFactory().lookupHome("vista/UserCollection",
    UserCollectionHome.class);
    UserHome userHome = (UserHome)
    EJBHomeFactory.getFactory().lookupHome("vista/User",UserHome.class);
    UserCollection uc = userCollectionHome.create();
    uc.setPassword(lname,pw, userHome);//assume that all lname are differents.
    } catch(HomeFactoryException hfe) {
    hfe.printStackTrace();
    throw new DelegateException(hfe);
    } catch(RemoteException re) {
    re.printStackTrace();
    throw new DelegateException(re);
    } catch(CreateException ce) {
    ce.printStackTrace();
    throw new DelegateException(ce);
    } catch(FinderException fe) {
    fe.printStackTrace();
    throw new UserNotFoundException();
    }//Do I have my class as a Singleton correctly???
    2)//Here is my First Frame that will call a Singleton to gather user information
    public A(Frame owner)
    super(owner, "User Personal Information",true);
    initScreen();
    loadPersonalInfo();
    * This method instantiates all the GUI widgets and places them into panels and
    * onto the frame.
    private void initScreen()
    txtFname = new JTextField(20);
    txtLname=new JTextField(20);
    btnsave =new JButton("Save");
    btnChange= new JButton("Click here to change PW");//when you click this button there will be a frame pop up for you to enter informaton..this iwll call class B
    JPanel pnlMain=new JPanel();
    JPanel pnlFname= new JPanel();
    pnlFname.setLayout(new BoxLayout(pnlFname, BoxLayout.X_AXIS));
    pnlFname.setBorder(BorderFactory.createEmptyBorder(0,87,0,90));
    pnlFname.add(new JLabel("First Name:"));
    pnlFname.add(Box.createRigidArea(new Dimension(5,0)));
    pnlFname.add(txtFname);
    JPanel pnlLname= new JPanel();
    pnlLname.setLayout(new BoxLayout(pnlLname, BoxLayout.X_AXIS));
    pnlLname.setBorder(BorderFactory.createEmptyBorder(0,87,0,90));
    pnlLname.add(new JLabel("Last Name:"));
    pnlLname.add(Box.createRigidArea(new Dimension(5,0)));
    pnlLname.add(txtLname);
    pnlMain.add(pnlFname);
    pnlMain.add(pnlLname);
    pnlMain.add(btnsave);
    pnlMain.add(btnChange");
    btnSave = new JButton("Save");
    btnSave.setActionCommand("SAVE");
    btnSave.addActionListener(this);
    btnCancel = new JButton("Cancel");
    btnCancel.setActionCommand("CANCEL");
    btnCancel.addActionListener(this);
    JPanel pnlBottom = new JPanel();
    pnlBottom.setLayout(new BoxLayout(pnlBottom, BoxLayout.X_AXIS));
    pnlBottom.setBorder(BorderFactory.createEmptyBorder(25,55,0,0));
    pnlBottom.add(btnSave);
    pnlBottom.add(Box.createRigidArea(new Dimension(25,0)));
    pnlBottom.add(btnCancel);
    pnlMain.add(pnlBottom);
    this.setContentPane( pnlMain);
    setSize(500,500);
    GraphicUtilities.center(this);
    theABC=ABC.getABC();
    //Do I call my ABC singleton class correctly??
    private void loadPersonalInfo()
    String ID= System.getProperty("user.name");
    SimpleUser user = null;
    try {
    user = ABC.getID(ID);
    //I tried to use method in ABC singleton class. IS this correctly call?
    } catch(UserNotFoundException nfe)
    JOptionPane.showMessageDialog(new JDialog(),"You have not yet registered.",
    "User Not Found",JOptionPane.WARNING_MESSAGE);
    System.exit(0);
    } catch(DelegateException de) {
    JOptionPane.showMessageDialog(new JDialog(),"You have not yet registered",JOptionPane.ERROR_MESSAGE);
    System.exit(0);
    currentUser = user;
    txtFname.setText(currentUser.getFirstName());
    txtLname.setText(currentUser.getLastName());
    //This information will be display in my textfields Fname and Lname
    //I can change my first and last name and hit button SAVE to save
    public void actionPerformed(ActionEvent e)
    if(e.getActionCommand().equals("SAVE")) submitChanges();
    if(e.getActionCommand().equals("CHANGE_PASSWORD")) {
    changepassword=new ChangePassword(new Frame(),name,badgeid);
    public void submitChanges(){
    String currentNTUsername = System.getProperty("user.name");
    SimpleUser user =null;
    try {
    user = theABC.getID(ID);
    user.setFirstName(txtFname.getText().trim());
    user.setLastName(txtLname.getText().trim());
    currentUser = user;
    theABC.updateUserInfo(currentUser);
    //IS this correctly if I want to use this method in singleton class ABC??
    } catch(UserNotFoundException nfe)
    JOptionPane.showMessageDialog(new JDialog(),"You have not yet registered",
    "User Not Found",JOptionPane.WARNING_MESSAGE);
    } catch(DelegateException de) {
    JOptionPane.showMessageDialog(new JDialog(),"You have not yet registered",JOptionPane.ERROR_MESSAGE);
    System.exit(0);
    this.setVisible(false);
    3) click on ChangePassword in my above GUI class A..will call this class B..and in this class B
    I need to access method in a Singleton class- ABC class,,DO i need to inititates it agian, if not what should I do? thanks
    package com.lockheed.vista.userinfo;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.border.*;
    import javax.swing.table.*;
    import javax.swing.tree.*;
    import java.util.StringTokenizer;
    import java.util.Vector;
    import java.io.*;
    import javax.swing.text.*;
    import javax.swing.text.html.*;
    import javax.swing.colorchooser.*;
    import javax.swing.filechooser.*;
    import javax.accessibility.*;
    import java.beans.*;
    import java.applet.*;
    import java.net.*;
    import org.apache.log4j.*;
    import com.lockheed.common.gui.GraphicUtilities;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.border.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import vista.user.UserServicesDelegate;
    import vista.user.SimpleUser;
    import vista.user.UserNotFoundException;
    import vista.user.*;
    import com.lockheed.common.ejb.*;
    import com.lockheed.common.gui.*;
    import com.lockheed.vista.publish.*;
    * This program allow users to change their Vista Web Center's password
    public class ChangePassword extends JDialog
    implements ActionListener{
    protected final Logger log = Logger.getLogger(getClass().getName());
    private UserServicesDelegate userServicesDelegate;
    private User currentUser = null;
    private JPasswordField txtPasswd, txtVerifyPW;
    private JButton btnSubmit,btnCancel;
    private JLabel lblName,lblBadgeID;
    private String strBadgeID="";
    * This is the constructor. It creates an instance of the ChangePassword
    * and calls the method to create and build the GUI.
    public ChangePassword(Frame owner,String name,String badgeid)
    super(owner, "Change Password",true);
    initScreen(name,badgeid);//build the GUI
    * This method instantiates all the GUI widgets and places them into panels and
    * onto the frame.
    private void initScreen(String strname,String strBadgeid)
    txtPasswd = new JPasswordField(20);
    txtVerifyPW=new JPasswordField(20);
    txtPasswd.setEchoChar('*');
    txtVerifyPW.setEchoChar('*');
    JPanel pnlMain=new JPanel();
    pnlMain.setLayout(new BoxLayout(pnlMain, BoxLayout.Y_AXIS));
    pnlMain.setBorder(BorderFactory.createEmptyBorder(20,0,20,0));
    JPanel pnlPW=new JPanel();
    pnlPW.setLayout(new BoxLayout(pnlPW, BoxLayout.X_AXIS));
    pnlPW.setBorder(BorderFactory.createEmptyBorder(0,96,0,30));
    pnlPW.add(new JLabel("Password:"));
    pnlPW.add(Box.createRigidArea(new Dimension(5,0)));
    pnlPW.add(txtPasswd);
    JPanel pnlVerifyPW=new JPanel();
    pnlVerifyPW.setLayout(new BoxLayout(pnlVerifyPW, BoxLayout.X_AXIS));
    pnlVerifyPW.setBorder(BorderFactory.createEmptyBorder(0,63,0,30));
    pnlVerifyPW.add(new JLabel("Verify Password:"));
    pnlVerifyPW.add(Box.createRigidArea(new Dimension(5,0)));
    pnlVerifyPW.add(txtVerifyPW);
    JPanel pnlTop= new JPanel();
    pnlTop.add(pnlPW);
    pnlTop.add(Box.createRigidArea(new Dimension(0,10)));
    pnlTop.add(pnlVerifyPW);
    pnlMain.add(pnlTop);
    btnSubmit = new JButton("Submit");
    btnSubmit.setActionCommand("SUBMIT");
    btnSubmit.addActionListener(this);
    btnCancel = new JButton("Cancel");
    btnCancel.setActionCommand("CANCEL");
    btnCancel.addActionListener(this);
    JPanel pnlBottom = new JPanel();
    pnlBottom.setLayout(new BoxLayout(pnlBottom, BoxLayout.X_AXIS));
    pnlBottom.setBorder(BorderFactory.createEmptyBorder(25,55,20,30));
    pnlBottom.add(btnSubmit);
    pnlBottom.add(Box.createRigidArea(new Dimension(25,0)));
    pnlBottom.add(btnCancel);
    pnlMain.add(pnlBottom);
    this.setContentPane( pnlMain);
    setSize(350,230);
    setVisible(true);
    public void actionPerformed(ActionEvent e)
    if(e.getActionCommand().equals("CANCEL")) this.setVisible(false);
    if(e.getActionCommand().equals("SUBMIT")) submitPW();
    * This method is called when the submit button is clicked. It allows user to change
    * their password.
    public void submitPW(){
    myABC= ABC.getABC();//Is this correct?
    char[] pw =txtPasswd.getPassword();
    String strPasswd="";
    for(int i=0;i<pw.length;i++){
    strPasswd=strPasswd+pw;
    char[] vpw =txtVerifyPW.getPassword();
    String strVerifyPW="";
    for(int i=0;i<vpw.length;i++){
    strVerifyPW=strVerifyPW+pw;
    if((strPasswd==null)||(strPasswd.length()==0)) {
    JOptionPane.showMessageDialog(new JDialog(),"You have not enter a password. Please try again.",
    "Invalid Password",JOptionPane.ERROR_MESSAGE);
    if((!strPasswd.equals(strVerifyPW)))
    //password and verify password do not match.
    JOptionPane.showMessageDialog(new JDialog(),"Your passwords do not match. Reenter and try again.",
    "Invalid Password",JOptionPane.ERROR_MESSAGE);
    try
    myABC.setUserPassword(strPasswd);//try to use a method in Singleton class
    txtPasswd.setText("");
    txtVerifyPW.setText("");
    this.setVisible(false);
    } catch(DelegateException e) {
    JOptionPane.showMessageDialog(new Frame(),
    "Error.",
    "Unable to change password information.",JOptionPane.WARNING_MESSAGE);
    } catch(UserNotFoundException e) {
    JOptionPane.showMessageDialog(new Frame(),
    "Error.",
    "Unable to change password information.",JOptionPane.WARNING_MESSAGE);
    And ofcourse I have other EJB classes to work with these classes.
    ***It compiles okey but when I ran, it say "NullPointerException"
    I think I call my Singleton wrong.
    Please help me.thanks

    1. When replying, use <reply>, don't post a new topic.
    2. Implementing a singleton is a frequently asked question. Search before you post.
    3. This is not a question about Swing. A more appropriate forum would be "New To Java Technology" or perhaps "Java Programming", but see point 1.
    4. When posting code, keep it short. It increases the chance of readers looking at it. And in composing your shorter version for the forum, you just may solve your problem.

  • Singleton class issue

    I have a singleton class. A method in this class creates an array of structures. This class is shared across different process. So there is a chance that some one unknowigly calls the method to create the array of structures and hence the member variable may now points to another array of structure.
    Is there any way in Java to restict invoking of a function only once.
    A static variable with a check will solve this issue, but any other method so that calling of method itself becomes invalid to avoid RT usage?.

    Hi,
    I think, I understood know.
    You want to have a singleton holding a defined number of other objects (your arrays).
    This objects (your arrays) are semantically singletons itsself, because they should be constructed only once and than reused.
    Assuming I interpreted right, see my comments inline below.
    I know that who ever participate in this discussion is
    pretty sure about singleton class. Some of the code
    what I gave was irretating as Martin pointed out. So
    let me try to give more transparent code snippet,Thanks, that helped.
    >
    My aim :- I need a global object which is going to
    hold some arrays(data structures). This should be
    shared across various threads. (forget about the
    synchronousation part here). All these arrays won't be
    of same size, so I need methods for each
    datastructures to initialise to its required size.That's a little bit part of your problem, see below.
    My wayforward :- Create the global object as
    singleton. This object has methods for initialising
    different data structures.OK, fine.
    What is my doubt :- please see the following code
    fragment,
    public class Singleton {
    private Singleton singleton;
    private Singleton() {
    public static Singleton getInstance() {
    if (singleton == null) {
    singleton = new Singleton();
    return singleton;
    //other methods for the class
    private someObjType1 myArray1 = null;
    private someObjType2 myArray2 = null;
    private someObjType3 myArray3 = null; // etc....This "smells" like an candidate for another data structure, so that you don't have a fixed number of array.
    F.E.
    // Associate class of array elements (someObjTypeX) as keys with arrays of someObjTypeX
    private Map arrayMap = new HashMap();>
    public void CreateArray1(int size) {
    if (myArray1 == null) {
    myArray1 = new someObjType1[size];
    }Using the map, you create array should look like
    public void CreateArray(Class clazzOfArrayElem, int size)
      Object arr = arrayMap.get(clazzOfArrayElem)
      if(arr == null)
        arr = java.lang.reflect.Array.newInstance(clazzOfArrayElem, size);
        arrayMap.put(clazzOfArrayElem, arr);
    }Additionally the "ugliness" of this method results from the problem, that don't know the size of arrays at compile time.
    So it seem to be preferable to use a dynamic structure like a Vector instead of array. Then you don't have the need to pass the size in the accessor method.
    Then you can use a "cleaner" accessor method like
    public Vector getVector(Class clazzOfArrayElem)
      Vector vec = arrayMap.get(clazzOfArrayElem)
      if(vec == null)
        vec = new Vector();
        arrayMap.put(clazzOfArrayElem, vec); 
    return vec;
    }If you want to expose an array oriented interface f.e. for type safety you can have an accessor like
    public Object[] getAsArray(Class clazzOfArrayElem)
      Vector vec = arrayMap.get(clazzOfArrayElem)
      if(vec == null)
        vec = new Vector();
        arrayMap.put(clazzOfArrayElem, vec);
      arr = java.lang.reflect.Array.newInstance(clazzOfArrayElem, 0);
      return (Object[])vec.toArray(arr);
    // Real typesafe accessors as needed following
    public SomeClass1[] getAsArrayOfSomeClass1()
      return (SomeClass1[])getAsArray(SomeClass1.class);
    /.....This accessor for array interface have the additional advantage, that they return a copy of the data (only the internal arrays, no the object within the arrays!), so that a least a client using your class doesn't have access to your internal data (with the Vector he has).
    >
    // similarly for other data structures...
    So here CreateArray1 method will work fine because of
    the check myArray1 == null.
    Actual question :- Can I remove this check and
    restrick call to CreateArray1 more than one time ?.No. As I understood you want to have something like a "only-use-once-method". There is no such thing in Java I know of.
    But I don't see the need to remove this check. Reference comparison should have no real impact to the performance.
    this is going to benifit me for some other cases
    also.How?
    Hope this helps.
    Martin

  • Question about synchronized singleton classes

    Hi,
    I have a singleton class, with only 1 method (which is static), I want access to that method to be synchronized, but someone suggested that I make my getInstance() method synchronized as well.
    Is this neccessary, or is it overkill?
    thanks!

    Example:
    static Instance getInstance() {
    if (instance == null) {
    instance = new Instance();
    return instance;
    }Two threads call it simultaneously:
    1. if (instance == null) { // evaluates true
    2. if (instance == null) { // evaluates true
    1. instance = new Instance(); // first instance
    2. instance = new Instance(); // second instance,
    deleting the reference to the first instance
    1. return instance; // which is not the originally
    created one but the second instance
    2. return instance;There's actually a worse consequence.
    1) T1 sees null
    2) T1 sets instance to point to where the object will live
    4) T2 sees non-null
    3) T2 returns, with a pointer to what's supposed to be an object, but isn't yet inited.
    4) T1 eventually inits the instance
    This can happen even if you use the "double check locking" pattern of synchronization.
    At least under the old memory model. I think the new JMM in effect in 5.0 (and possibly later 1.4) versions fixes it. I don't know if the fact that it can happen in absence of sync/DCL is an error or not, so I'm not sure if that's addressed in the new JMM, or if it's only the synced case that was a bug. (That is, it might be okay that it happens without syncing.)

  • Singleton class with static method

    Hi,
    I have made a fairly simple singletion class STClass. EX:
    Consider tow cases
    CASE-1:
    private static STClass singleInstance;
    private static int i;
    private STClass()
    public static STClass instance()
         if (singleInstance == null)
              singleInstance = new STClass();
              loadConfigFile("XYZ");
         return singleInstance;
    private static void loadConfigFile(String fileName)
         //SOME CODE in which use private variable "i"
    CASE-2:
    private static STClass singleInstance;
    private int i;
    private STClass()
         loadConfigFile("XYZ");
    public static STClass instance()
         if (singleInstance == null)
              singleInstance = new STClass();
         return singleInstance;
    private void loadConfigFile(String fileName)
         //SOME CODE in which use private variable "i"
    What is the differnce between two case and which one will be best and why???
    Someone told me "If u keep variables and methods as static the the whole purpose of singleton class is defeated"
    please justify this statement

    It seems to me that this way should be more "correct":
    public class STClass {
    private static STClass singleInstance;
    private int i;
    private STClass() {
    public static STClass getInstance() {
    if (singleInstance == null) {
    singleInstance = new STClass();
    singleInstance.loadConfigFile("XYZ");
    return singleInstance;
    private void loadConfigFile(String fileName) {
    //SOME CODE in which use private variable "i"
    }And it is also compatible with your CASE-2.
    Hope this helped,
    Regards.I wouldnot agree with this piece of code here because of JMM bug. check this
    http://www.javaworld.com/jw-02-2001/jw-0209-double-p2.html
    What about proposing your own version, explained ?...

  • Singleton class + JTable mouseClicked

    Hi,
    I have a problem with this topic:
    singleton class OR create new class and use one function (not a static func) of this class from else class.
    I have singleton class that return JScrollPane with table, in this table I have tasks..
    in this class I have: public void mouseClicked(MouseEvent e) function.
    when the user clicked --> I create another JTable (table with sub tasks)
    and if the user clicked in this table, I create another JTable (table with sub sub tasks).............................
    I need your help because: if the class that create a JTable singleton type, then I can not get another mouseClicked of jtable that below the new jtable (I can't get another mouseClicked of sub tasks table if I created the sub sub tasks table...).
    But, if I create everytime NEW class that return the scroll JTable --> I get different problem:
    I need to use with some functions from scroll JTable class and I don't know how to do it..I can't do: TaskTable.getInstance().getMyFunc();
    This function must to be in this class, and not static!
    I'm new :) maybe I don't know some else way to get function from regular class.
    Sorry about my english.
    I'm really need your help :)
    Thasks.

    ..if I create everytime NEW class that return the scroll JTable --> I get different problem:
    I need to use with some functions from scroll JTable class and I don't know how to do it..
    TaskTable t1 = new TaskTable();
    t1.getMyFunc();

  • Any adverse effects from singleton classes?

    We're trying to decide whether it is a good/bad/indifferent idea to use
    singleton classes in various places in an application (servlets, session
    EJBs, BMP entity EJBs), in a clustered environment. Our app designers
    have a number of different potential uses in mind, such as storing some
    rarely changed data, and localised caches. We're happy with the
    restriction that they obviously wouldn't be replicated. However, we're
    not sure about what other implications there might be, especially when
    the thing is scaled up. Questions that spring to mind include:
    - any inbuilt synchronisation that WL may do (if the singleton had to
    dive off to a database to get some further info we wouldn't necessarily
    want to have other callers to it synchronise at that point)
    - the effect on the JVM if we tie up some of its virtual memory
    - any other considerations
    Note that they are considering using this technique in both the web app
    and the ejbs (which will reside in different clusters).
    Are there any guidelines available for the use of singletons,
    particularly from a performance point of view?
    Thanks
    Chris

    For caching in clustering, read only entity beans are best bet.
    You must not bind a cach ( HashMap or soemthing) object in JNDI tree in
    clustering. This could lead to mess as this binding is not cluster aware. You
    might see conflict messages in your log file or your local bidning could fail
    in one or other server depending upon timing.
    Other than that as long as you don't have synchronization in singleton classes
    that leads to deadlocks, there should not be a problem.
    Viresh Garg
    Principal Developer Relations Emgineer
    BEA Systems
    Larry Presswood wrote:
    Well duno if this helps but their new Jolt Pool Manager is a singleton
    class.
    Also you could use JNDI as a data cache but be careful as it replicates
    across
    the cluster.
    Chris Palmer wrote:
    We're trying to decide whether it is a good/bad/indifferent idea to use
    singleton classes in various places in an application (servlets, session
    EJBs, BMP entity EJBs), in a clustered environment. Our app designers
    have a number of different potential uses in mind, such as storing some
    rarely changed data, and localised caches. We're happy with the
    restriction that they obviously wouldn't be replicated. However, we're
    not sure about what other implications there might be, especially when
    the thing is scaled up. Questions that spring to mind include:
    - any inbuilt synchronisation that WL may do (if the singleton had to
    dive off to a database to get some further info we wouldn't necessarily
    want to have other callers to it synchronise at that point)
    - the effect on the JVM if we tie up some of its virtual memory
    - any other considerations
    Note that they are considering using this technique in both the web app
    and the ejbs (which will reside in different clusters).
    Are there any guidelines available for the use of singletons,
    particularly from a performance point of view?
    Thanks
    Chris

  • Synchronized Instance Methods in Singleton Class

    If I've a TransactionManager class that's a singleton; meaning one manager handling clients' transaction requests, do I need to synchronize all of the instance methods within that singleton class?
    My understanding is that I should; otherwise, there's a chance of data corruption when one thread tries to update, but another thread tries to delete the same record at the same time.

    Let's say that you have a singleton that is handling
    the printing in a desktop application. This could be
    time consuming and it will not probably be used too
    often. What's time consuming about instantiating the object?
    On the other hand you could not say that it
    will never be used.Exactly. If that were so, why write it?
    In a web application, response time is much more
    important than initialization time (which can be
    easily ignored). Never ignored. It's just a question of when you want to pay.
    Web app as opposed to desktop app? Does response time not matter for them?
    In this case, of course, eager
    initialization makes much more sense.I'm arguing that eager initialization always makes more sense. Lazy for singletons ought to be the exception, not the norm.
    %

  • Singleton class instantiated several times

    Hi all,
    I am trying to implement an inter-applet communication using a singleton class for registering the applets. The applets are in different frames on my browser; they are placed in the same directory and they use the same java console, so I am pretty sure they are running on the same JVM...
    However, when I register my applets, every applet creates its "own" registry class. I have put a message in the constructor of the register class to check what's happening:
    public class AppletRegistry extends Applet 
        //static hashtable maintaining the applet map
        private static Hashtable appletMap;
        private static int ct=0;
        protected static AppletRegistry registry;
        protected AppletRegistry()
            appletMap = new Hashtable();
    //  Returns the long instance of the registry. If there isn't a registry
    //  yet, it creates one.
          public synchronized static AppletRegistry instance()
               if (registry == null) {
                         System.out.println("new register");
                    registry = new AppletRegistry();
               return registry;
        //registers the given applet
        public void register(String name, Applet applet)
            appletMap.put(name, applet);
            ct++;
            System.out.println("Register: "+name+" "+Integer.toString(ct));
    }The output "new register" appears for every applet I register... What am I doing wrong?
    Thea

    I must admit that I never heard of classloader until
    now :-( (learning java for two or three months). Do
    you know a good tutorial about using classloaders? I
    have no idea where to start checking which
    classloaders are used.
    Thanks!
    TheaHi,
    I don't think there are much you can do about it. Two different applets can't share an instance.
    /Kaj

  • Singleton class within Container

    Let me extend my apologies now if this is to simple of a question for the forum.
    Here is my design issue. We are within a session bean (Stateless) and each session bean will need access to a Singleton class which possesses reference data (has a find method). This Singleton class must be static as we do not wish to replicate the amount of data involved.
    Here is my concern. Based on the fact the EJB container has created 10 session beans which must access this Singleton class and the methods within it, I "think" there will be a concurrency issue with this design.
    Can a EJB guru shade some light on this issue for me?
    Thanks in advance!

    If the the singleton class is used for multiple read and only one specific bean does a write, I dont think there should be a problem.
    However, if there are multiple read and write scenarios, then offcourse concurrency is an issue.
    What kind of data are using inside the single ton class. If you are using a hashtable or Vector inside, they take care of concurreny , as they are synchronized.
    Or else another way I could think of is
    Create a statefull session bean, instead of a java object for your singleton. Make the maximum and minimum cache size to 1.
    This will take care of the object to be singleton. And the bean would take care of the concurreny.
    Just my thoughts, am not an expert,

  • Inherit Singleton class?

    hi there,
    We are learning Java at University and are supposed to develop a program to manage an art exhibition.
    The art exhibition is limited to 100 Objects (paintings and sculptures). Every object has a name, a value, an insurance, etc. and type specific attributes.
    So basically I've got three classes: Object, Painting extends Object and Sculpture extends Object.
    Now the easy way to limit the number of Objects to 100 would be to store them in an array with 100 fields.
    My idea was, that its way more elegant to have Object as a singleton class with 100 instances. But since I made the Object constructor private I cant extend Painting and Sculpture to Object any more.
    Is there a way round that?
    My singleton class is based on this example: http://www.javaworld.com/javaworld/javaqa/2001-11/01-qa-1102-singleton.html

    100 really puts the 'multi' in multi-ton, no? :^)
    And the "ton" as well :o)
    But it doesn't solve my problem of inheritance since the constructor is private.
    You don't need a multiton. It's inappropriate. You need a restricted collection.
    Let's imagine a few scenarios for a moment.
    You have an exhibition with a capacity of 100 artefacts, and it is fully populated. Now let's say someone submits an artefact for the exhibition, and if it's more interesting than the current least interesting artefact, the old one is removed and the new one is added in its plaace.
    Your 100-instance multiton can't cope with that: the additional artefact simply cannot exist.
    Let's also imagine that you want to open a second exhibition. Your multiton can't cope with that: at the most they will have 100 artefacts to share between them.
    Does that make sense?
    Think about the real world. There are lots of artefacts. Exhibitions are of limited size.

  • Singleton class in WebLogic Cluster

    Hi,
    We have an application set-up in a weblogic cluster.
    We have a singleton class in the application.
    Since we have two managed servers in the cluster the singleton has two instances, one in each server.
    So the basic purpose of use of singleton is lost.
    Could anyone please give some alternative implementation.
    Regards
    Gunajit K

    One alternative is to set up some type of centralized store for the information you are trying to share between VMs. I would look at what you are trying to do with the singleton and make some descisions.
    Specifically, I would at least look at how much access you will need to the data, how much network traffic it will take to send it to each node in your cluster, and what kind of transactional integrity you require.
    A JMS publish/subscribe topic would be a good solution if you are caching some type of data that changes relatively infrequently. You could set this up yourself or check out SpiritSoft's Spirit Cache product (no, I don't work for SpiritSoft).
    Or you could simply store the information in some type of database and access it via EJBs or JDBC or whatever you like.
    Clearly, the performance of such a store will not be as quick as the in-memory access a Singleton provides inside a single JVM. So be careful about what solution you choose and be sure to optimize its performance as best you can.

  • The latest version does not show the security pad-lock, concerned about on-line purchases.

    When you go to make purchases you always had a pad-lock in the lower right corner letting you know it was secure. This latest version does not and I'm concerned about on-line purchases.

    In Firefox 4 you no longer have the Status bar that showed the padlock in previous Firefox versions.<br />
    The padlock only shows that there is a secure connection and doesn't guarantee that you are connected to the right server.<br />
    So you might still be connected to the wrong server if you make a typo in the URL and someone has claimed that mistyped URL.<br />
    The functionality of the padlock has been replaced by the [[Site Identity Button]] on the left end of the location bar.
    See also:
    * http://www.dria.org/wordpress/archives/2008/05/06/635/
    * https://support.mozilla.com/kb/Site+Identity+Button
    You can use this extension to get a padlock on the location bar.
    *Padlock: https://addons.mozilla.org/firefox/addon/padlock-icon/

  • What is Singletone class?

    I would desire to apprehend the brief description about usage of Singletone class and where it can be applied.plz help me

    example
    public class Singleton {
    private static Singleton INSTANCE = null;
    // Private constructor suppresses
    // default public constructor
    private Singleton() {}
    //synchronized creator to defend against
    multi-threading issues
    //another if check here to avoid multiple
    instantiation
    private synchronized static void createInstance()
    if (INSTANCE == null) {
    INSTANCE = new Singleton();
    public static Singleton getInstance() {
    if (INSTANCE == null) createInstance();
    return INSTANCE;
    Thanks
    Siju Kurian
    Starmark service ltdDon't use this example in real applications, it has a serious flaw. Read http://java.sun.com/developer/technicalArticles/Programming/singletons/ .This example is implementation of Double-checked locking, which lacks proper synchronization.
    In almost all cases, solution provided by georgemc is applicable - it is simple and provides lazy initialization unless class have other non-private static methods/fields or non-private constructors (which may trigger initialization of class when used) (JLS, 12.4.1).

  • Concerned about new ML....should I wait?

    I want to buy 15" MBP or Air but am concerned about the new ML op. system. Overall, are people pleased with ML on a brand new machine (not an upgrade)? Would it be wise to wait for problems (as seen on Support Discussions) to get worked out?
    I'm a creative director and do writing and some design work, which means I'll be running Creative Suite on my next laptop. The light weight and curved wrist rest of the Air appeals to me but I'm wondering about the speed of the MBP over the Air. I'd love to hear opinions on which new MacBook to buy.
    What is difference between flash storage vs  hard drive vs solid state drive? What is a Super Drive? Duo vs Quad core? Headphone port vs Audio In/Out?
    Also concerned about ML eating up time available when on battery only. Is this true on new MacBooks or just upgrades to ML on older machines?
    Thanks!

    Gretchen wrote:
    What is difference between flash storage vs  hard drive vs solid state drive? What is a Super Drive? Duo vs Quad core? Headphone port vs Audio In/Out?
    A hard drive has spinning platters and, opposed to an SSD, is very slow. SSDs and flash storage are pretty much the same - an SSD is simply flash storage enclosed in a case that will fit in a standard hard drive slot. Apple's prices on SSDs are outrageous. If you get a 15" you can buy a similar SSD that Apple sells for much less.
    A SuperDrive is simply a drive that allows you to read and write optical disks (CDs and DVDs). I consider mine a must but some people rarely use them and opt for an external optical drive - from Apple or a third-party. I use mine primarily for archival storage but also ripping the occasional CD to iTunes or watching a movie. Some can do without a built-in SuperDrive and just use an external, some, like myself, prefer to have it built-in.
    A quad core processor simply has four 'mini-processors' built into a single processor. A duo has only two. The quad core is much faster than a dual core.
    The Air (and 13") have a single audio-out headphone jack. The 15" has both audio in and audio out jacks. I prefer the latter.
    Also concerned about ML eating up time available when on battery only. Is this true on new MacBooks or just upgrades to ML on older machines?
    The problem with low battery life first crept up with Lion and then got worse - for some users - after the Mountain Lion update. I haven't had any problems but a number of users have and there seems to rhyme nor reason - it's not specific to any one model of machine nor software application. Apple knows of the problem and is, presumably, working o a fix. You probably have something like a 1 in 100,000 chance (if that) of having problems with your battery life.
    I also run CS6 on my late 2011 15" MacBook Pro - the CS6 Design and Web Premium suite. It's quite speedy on my machine (but then I have 16Gb of RAM and a 512GB SSD).
    Hope I was able to answer a few questions...
    Clinton

Maybe you are looking for