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

Similar Messages

  • Any adverse effect of an expired SSL certificate

    I wanted to understand if there are any adverse effects if the SSL certificate has expired. Going logically, the communication channel between server and client browser would not be secure. I would give an example to this, if the site is say https://www.xyz.com
    1) Would the site be accessible if the SSL certificate has expired, I guess yes?
    2) Any other adverse effects?
    I hope, I have been able to explain the question clearly.
    Requesting a reply to my query.
    Regards

    Thanks for your update. It is connecting using https. The SSL certificate is not generated at OS (RHEL) level but is done most probably at Tomcat server level which I am trying to check from the developers.
    Regards

  • IPv4 Backbone Baby Jumbo MTU size - any adverse effect?

    Hello.
    Is there any complication or adverse effect, setting IPv4/MPLS backbone GE link MTU size bigger than the Ethernet De facto of 1500, in the ASR9000 IOX-XR 4.3.x? What would be practical size? 4470, 8192? We have customers request to set 1800 but too odd value. What is the value the ASR9K (Trident LC with RSP, not 440) and LCs supports?
    Much appreciate for your support.
    Thanks,
    Intopian.

    That is correct Won, there are other advantages also as you noted.
    For routing protocols:
    OSPF uses it to fill its DBD's do both sides need to ahve the same MTU size,
    same applies to ISIS.
    RIP doesnt really care, although it can pack more updates in a single packet
    BGP, using TCP, will use the MTU to adjust its MSS value so BGP benefits from this also big time.
    As for delay on voip, yes theoretically, if the link speed is low enough, serialization delay of a large mtu packet may induce jitter on the high priority voip packet. But with 1500 bytes, the "fragment" size should be adjusted at 750k (so half T1 speed) only. With the majority circuits operating now at 1G, 10G etc, this fragment size requirement is almost no longer there as the serialization delay is so low at these speeds.
    Other then very low end CPE's or very old devices that dont like larger MTU's (eg very old PA's in the 7200) there is really no worry anymore increasing the MTU size.
    I dont think there is a formal doc on this, but I am sure if google it, you can find recommendations from other folks
    on what they have done/seen etc.
    regards
    xander
    Xander Thuijs CCIE #6775
    Principal Engineer 
    ASR9000, CRS, NCS6000 & IOS-XR

  • Quicktime 7.0.3 - any adverse effects?

    Apple just released QT 7.0.3 via software update.
    Has anyone updated and experienced and adverse effects with FCP 4.5 or 5.0.2?
    I will update as soon as I am finished with my current project.

    Brant,
    Every major version increase has necessitated a re-purchase of the pro key.
    If you're running Quicktime 6 Pro, and you upgrade to 7.0.3, you'll need to re-purchase.
    If you're running 7.0.2 and upgrade to 7.0.3, you won't need to re-purchase.
    If you have purchased a pro key for Quicktime 7, you won't need to re-purchase a pro key until Quicktime 8 comes out.

  • Are there any ill effects from removing Garage Band?

    Can I uninstall Garage Band with no ill effects to my operating system?  I don't want it--but if I'm going to mess something up by removing it, I'll leave it.

    No problem at all. Drag the Garageband icon from the Applications folder to the trash, then go to Macintosh HD > Library > Application Support and drag the Garageband folder from there to the trash.
    Similarly with your home folder > Library > Application Support > Garageband.
    In home folder > Library > Preferences there are 3 plist files;
    It doesn't matter if you leave them, as they use little space, but trash them if you're comfortable doing so.
    Apple Loops;
    There's also a Garageband folder in home > Music
    Macintosh HD > Users > shared > GarageBand Demo Songs.
    Also any third party loops (Dance Packs etc.) which may be lurking in your home folder or Applications folder. (Only if you've installed them).
    Might be a few other bits scattered around, but nothing to worry about.

  • Can not access the Instance Data of a Singleton class from MBean

    I am working against the deadline and i am sweating now. From past few days i have been working on a problem and now its the time to shout out.
    I have an application (let's call it "APP") and i have a "PerformanceStatistics" MBean written for APP. I also have a Singleton Data class (let's call it "SDATA") which provides some data for the MBean to access and calculate some application runtime stuff. Thus during the application startup and then in the application lifecysle, i will be adding data to the SDATA instance.So, this SDATA instance always has the data.
    Now, the problem is that i am not able to access any of the data or data structures from the PerformanceStatistics MBean. if i check the data structures when i am adding the data, all the structures contains data. But when i call this singleton instance from the MBean, am kind of having the empty data.
    Can anyone explain or have hints on what's happening ? Any help will be appreciated.
    I tried all sorts of DATA class being final and all methods being synchronized, static, ect.,, just to make sure. But no luck till now.
    Another unfortunate thing is that, i some times get different "ServicePerformanceData " instances (i.e. when i print the ServicePerformanceData.getInstance() they are different at different times). Not sure whats happening. I am running this application in WebLogic server and using the JConsole.
    Please see the detailed problem at @ http://stackoverflow.com/questions/1151117/can-not-access-the-instance-data-of-a-singleton-class-from-mbean
    I see related problems but no real solutions. Appreciate if anyone can throw in ideas.
    http://www.velocityreviews.com/forums/t135852-rmi-singletons-and-multiple-classloaders-in-weblogic.html
    http://www.theserverside.com/discussions/thread.tss?thread_id=12194
    http://www.jguru.com/faq/view.jsp?EID=1051835
    Thanks,
    Krishna

    I am working against the deadline and i am sweating now. From past few days i have been working on a problem and now its the time to shout out.
    I have an application (let's call it "APP") and i have a "PerformanceStatistics" MBean written for APP. I also have a Singleton Data class (let's call it "SDATA") which provides some data for the MBean to access and calculate some application runtime stuff. Thus during the application startup and then in the application lifecysle, i will be adding data to the SDATA instance.So, this SDATA instance always has the data.
    Now, the problem is that i am not able to access any of the data or data structures from the PerformanceStatistics MBean. if i check the data structures when i am adding the data, all the structures contains data. But when i call this singleton instance from the MBean, am kind of having the empty data.
    Can anyone explain or have hints on what's happening ? Any help will be appreciated.
    I tried all sorts of DATA class being final and all methods being synchronized, static, ect.,, just to make sure. But no luck till now.
    Another unfortunate thing is that, i some times get different "ServicePerformanceData " instances (i.e. when i print the ServicePerformanceData.getInstance() they are different at different times). Not sure whats happening. I am running this application in WebLogic server and using the JConsole.
    Please see the detailed problem at @ http://stackoverflow.com/questions/1151117/can-not-access-the-instance-data-of-a-singleton-class-from-mbean
    I see related problems but no real solutions. Appreciate if anyone can throw in ideas.
    http://www.velocityreviews.com/forums/t135852-rmi-singletons-and-multiple-classloaders-in-weblogic.html
    http://www.theserverside.com/discussions/thread.tss?thread_id=12194
    http://www.jguru.com/faq/view.jsp?EID=1051835
    Thanks,
    Krishna

  • Hey guyz.. i wanna ask if i get an updated version from itunes when i plug my iPhone into the Pc, i get a letter tells me that there is an update for your iPhone ... i wanna ask is it safe to download ?? and does it make any side effects on longTerm using

    hey guyz.. i wanna ask if i get an updated version from itunes when i plug my iPhone into the Pc, i get a letter tells me that there is an update for your iPhone ... i wanna ask is it safe to download ?? and does it make any side effects on longTerm using ??

    It is safe to download if your phone is not jailbroken. Before you download it, however, take some precautions:
    Reboot your computer
    Disable your antivirus and firewall
    Connect the phone cable to a USB port directly on the computer, not a hub
    Before updating right click on the name of the phone in iTunes and choose "Backup"
    When you are given the choice choose "Download only", not "Download and Update"
    After the download completes successfully click the Update button to install it.
    Most of these steps are just being overly cautious, as most people ignore them and have no problems. But occasionally the extra steps save grief.

  • Is there any way to retrieve java source ie(.java) from java class (.class)

    I Lost my all java source file during system crash.But i have all class files.I want to get source files
    ie all .java files from that class.Is there any way to get my source from complied classs.
    Help me!!

    The short answer is no! But unofficially you can. The possibility (and the limitations) of the decompilation come from the class file format's being well-defined and open (available). So I do not think decompilation is very much "unofficial".
    You might, howebver, think decompilation is "unofficial", because there is no decomplier bundled with the "official" JDK (SDK): javap is useful but provides less than the decompilers.

  • How can I to control any element of my GUI from another class?

    How can I to control any element of my GUI from another class?

    For that, you need the external class to have the reference to your element.. If your idea is to change basic properties like width, height etc.. then you can have the constructor of the external class to take the object of the parent of your class as the parameter and modify ..
    However, if the properties to be altered/accessed are custom to your element, then you will have to have the class accept an object of your class as the parameter. No other option..
    What exactly is your requirement?

  • Place of Singleton class in OO Design

    Hi
    Can any body make me clear on, why we make use of Singleton Class and how it is related to Object Oriented world.
    Thanks,
    Prasanth

    Personally, I�ve never seen a case where singletons
    are being badly used. In this forum, I�ve always been
    reading a lot of people saying that Singleton is
    anti-pattern, Singleton is evil, Singleton is
    abusively implemented, etc, etc. It�s very easy to
    say those things, perhaps because of some authorities
    who endorse what you say, but nobody has said WHY
    EXACTLY Singletons are bad.I thought I did say exactly that in this thread.
    Let me try again.
    Some people believe that simply by using Singletons that their designs follow OO principals. In effect it is quite possible to create an entire application or most of an application using procedural programming by using singletons.
    In terms of OO it is considered a bad design when the design is procedural.
    >
    If it is anti-pattern, then it would be better if it
    were not used. But if it is in fact used and it is
    considered good sometimes, then we can conclude that
    it is not an anti-pattern. This is just logic.
    Incorrect. Everything can be both abused and used correctly.
    However at some point the incorrect usage and the complications from that outweigh the benefits of the correct usage. That might be a subjective or objective determination.
    Examples of this.
    1. In two shops where I worked that used unix and C++ exclusively the use of operator overloading and multiple inheritence was completely banned. The majority of developers (I never found one that disagreed) believed that the usage of those two would be detrimental to the code that was being created.
    2. The creators of java decided that pointers should not be allowed.
    Now it could be that that all of those people are wrong. Or it could be that many of them were going on ancedotal evidence learned either first hand, second hand (or many hands) and yet that evidence was wrong.
    Myself I suspect it would be very expensive to determine objectively many thing that technological decisions are made upon. So one is left with whatever one can find.
    I�ve already googleg for some information, but what I
    found are just lots of sites that repeat what a lot
    of people here say, more or less.
    I think people have to have a good explanation for
    what they say.Not necessarily. Most larger technological decisions are often made with only subjective knowledge. Many people insist that unix is more stable than windows. Or that java/C++/C# (pick one) is better than java/C++/C3 (pick another) with seldom any more reason than just because they like one or the other.
    Finally you might note that I haven't seen the abuse that is being reported here. I do however recognize the possibility that it could be occurring.

  • Calling a backend bean method from another class

    Hi,
    I'm new in JSF & in this forum so maybe this question is already aswer.
    My problem is that I made a jsf component to deal with a tree menu. The resources in the leaf nodes of the menu are stored in a action calling pattern (i.e.: #{myBean.myMethod}) & I'm looking for a way to bind & execute the call from the class of the component that treats the events.
    I suppose that I need to get the current instance of the context, get the bean location, instance it & invoke the method, but I don�t know how.
    I have another more question, may this resource invocation have any kind of undesirable side effect, I meen, it's me & not the faces context who is making the call so I'm not sure if that the best way to solve the problem.
    Thanks in advance.

    If I understand what you're saying correctly... you have a component which enables a user to select an action (leaf nodes in the menu). You are processing this selection in your component and now have a EL expression that looks like #{myBean.myMethod}. You now need to know how to use that expression from Java code to invoke it. Is that correct?
    If so:
    FacesContext ctx = FacesContext.getCurrentInstance();
    MethodBinding mb = ctx.getApplication().createMethodBinding("#{myBean.myMethod}", new Class[] {});
    mb.invoke(ctx, null);
    This should do what you want. If you need to pass arguments to the method, you can do that as well... you need to pass in the types via the Class[], and the objects via an Object[] instead of null.
    Note also that the API's for EL change for JSF 1.2 to the standard EL API's, however, the older API's (above) are still supported.
    Ken Paulsen
    https://jsftemplating.dev.java.net

  • How to make Singleton Class secure

    I have a Singleton class which I instantiate using reflection by a call to a public getInstance method that return the object from a private constructor. I have to use reflection as I dont have any other options since my class instantiation is decided on runtime. How will I secure other form instantiating the same class again by using reflection on my private constructor? Any ideas?

    How much do these different implementations of your singleton have in common? What I'm getting at is, is there some common code you could extract out of them all, and make that a singleton in it's own right? Needing to do this sort of hacking is often a sign you're fudging something together, that could be solved more elegantly. We use the Singleton pattern generally when the state of the object needs to exist exactly once. Can you extract that from the disparate objects?
    The singleton classes that I load do not have anything in common. They are all similar but unique, and independant in their own respect. I will have to decide only on what singleton object I have to load in runtime, based on certain criterion. This is done by reflection, by a call to the public getInstance() method of the respective singleton classes, since I am deciding on runtime. My problem is that can I prevent others from accessing my private constructor from outside the class using reflection, which enables them to create another duplicate object. Can I restrict them to use only my getInstance() method instead?? I know this is hacking to access the private members, but I want to know whether there is any way where I can restrict this hacking???In the above code I dont want these statements to work at any case
    java.lang.reflect.Constructor[] c = cl.getDeclaredConstructors();
    c[0].setAccessible(true);
    A anotherA  = (A) c[0].newInstance(new Object[]{"Duplicate"});

  • TestStand create different object for singleton class

    Hi all,
    we have a singleton class which has some functions used to do testing a harware.
    Our main Exe will create an object for that singleton class(which opens Com1 port and communicate with hardware). so the Exe will do basic communication test with hardware it is working well. We are using Teststand operator interface to do various testing by using sequence files. Main exe will use teststand usercontrols to execute tests when the user clicks Testbutton. after that, teststand try to create an object for that singleton but it returns new object not the existing one which is created by EXE. So it throwing me exeception "Com1 port access denied." (since we created object for signleton class @ very first in EXE)
    My question is Since that teststand runs in a separate Appdoamin will the singltonclass create separate object for different appdomain? if so is there any solution to reslove this?
    Hope i clearly explained my probs.
    Thanks in advance
    Srini 

    Hi Srini,
    How are you calling the executable?  From a Call Executable step?  Or are you using another means of calling it?   Also, why is TestStand trying to recreate the object?  As long as you have the correct handle to the object I don't think it matters what app domain you are in.
    Regards,
    jigg
    CTA, CLA
    teststandhelp.com
    ~Will work for kudos and/or BBQ~

  • 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

  • Any detrimental effects on unhiding iPod_Control folder?

    There are many guides on the internet which direct one to set folders to show hidden directories in order for music to be accessed on the iPod from a compy. Here's my issue.
    On the computers I use during my classes, we're very restricted. I cannot install iTunes since I don't have the permissions. I can't eject the iPod properly since I don't even have those permissions. However, the more relevant issue is that I can't get to Options for folders, so I can't make hidden directories show.
    During work with these computers, I'd love to be able to listen to my music while using my iPod as something akin to a jump drive. Since I can't do that, I'd love to be able to get to my music but I can't even do that since I don't have permissions to access folders directly through the address bar on Internet Explorer.
    My question is this. At home, I can make "iPod_Control" hidden or unhidden. If I make it unhidden, will this have consequences to the iPod working, or?
    Dell   Windows XP  

    It won't really have any adverse consequences (unless you start making changes to the contents of the folder), but you might have a hard time navigating to the tracks you want.
    iTunes renames the folders and filenames when they are synced to the iPod, making it very difficult to know what a track is by looking at the filename.

Maybe you are looking for

  • Increase in stock

    Dear Experts,        We are implementing for Dairy and here they procure milk and kept in several SILO, at the end of the day they wash SILO with water, but all water is not drained off, so some up to 2-3 thousand liter water remains, and next day wh

  • Question about Aperture slide shows

    Question about Aperture slide shows. How can I eliminate banding in a blue sky when photos are displayed in Aperture Slide shows?

  • What are the best import settings for iTunes - AAC 160 / AAC 192 / MP3??

    Hi I originally imported all my treasured CDs to iTunes several years ago, and they've served me well (AAC 128 - default setting) but in recent times hard-drive sizes have trebled and my much loved iTunes Library has not been updated. I am thinking o

  • VIEWSONIC MONITOR

    Hi all! I am considering buying the ViewSonic VX2240w 22" LCD monitor http://www.viewsonic.com/products/lcddisplays/xseries/VX2240w/ Do you think it will look alright when I hook it up w/ DVI/VGA cable with my 15" MacBook Pro (lowest MBP model) I'll

  • Canon 9950F scanner - required drivers and sw for iMac Mountain Lions

    how can I connect my Canon scanner ( model 9950F ) to my new iMac ?