How to implement a singleton class across apps in a managed server}

Hi ,
I tried implementing a singleton class , and then invoking the same in a filter class.
Both are then deployed as a web app (war file) in a managed server.
I created a similar app , deployed the same as another app in the same managed server .
I have a logger running which logs the singleton instances as well.
But am getting two instances of the singleton class in the two apps - not the same .
I was under the impression that , a singleton is loaded in the class loader level , and since all apps under the same managed server used the same JVM , singleton will only get initialized once.
Am i missing something here ? or did i implement it wrong..?
public class Test
   private static Test ref ;
   private DataSource X; 
   static int Y;
   long Z ;  
   private Test ()
      // Singleton
       Z= 100 ;
   public static synchronized Test getinstance()  throws NamingException, SQLException
      if(ref == null)
         ref = new Test() ;        
         InitialContext ic = new InitialContext();
         ref.X = (DataSource)ic.lookup ("jdbc/Views");
      return ref ;       
   public Object clone()throws CloneNotSupportedException
       throw new CloneNotSupportedException();
   public int sampleMethod (int X) throws SQLException
public final class Filter implements Filter
     public void doFilter(ServletRequest request, ServletResponse response,FilterChain chain) throws IOException, ServletException
          try
               Test ref = Test.getinstance();
               log.logNow(ref.toString());
}Edited by: Tom on Dec 8, 2010 2:45 PM
Edited by: Tom on Dec 8, 2010 2:46 PM

Tom wrote:
Hi ,
I tried implementing a singleton class , and then invoking the same in a filter class.
Both are then deployed as a web app (war file) in a managed server.
I created a similar app , deployed the same as another app in the same managed server .
I have a logger running which logs the singleton instances as well.
But am getting two instances of the singleton class in the two apps - not the same .Two apps = two instances.
Basically by definition.
>
I was under the impression that , a singleton is loaded in the class loader level , and since all apps under the same managed server used the same JVM , singleton will only get initialized once. A class is loaded by a class loader.
Any class loader that loads a class, by definition loads the class.
A VM can have many class loaders. And far as I know every JEE server in existance that anyone uses, uses class loaders.
And finally there might be a problem with the architecture/design of a JEE system which has two applications but which is trying to solve it with a singleton. That suggests a there might be concept problem with understanding what an "app" is in the first place.

Similar Messages

  • How to implement a java class in my form .

    Hi All ,
    I'm trying to create a Button or a Bean Area Item and Implement a class to it on the ( IMPLEMENTATION CLASS ) property such as ( oracle.forms.demos.RoundedButton ) class . but it doesn't work ... please tell me how to implement such a class to my button .
    Thanx a lot for your help.
    AIN
    null

    hi [email protected]
    tell me my friend .. how can i extend
    the standard Forms button in Java ? ... what is the tool for that ... can you explain more please .. or can you give me a full example ... i don't have any expereience on that .. i'm waiting for your reply .
    Thanx a lot for your cooperation .
    Ali
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by [email protected]:
    Henrik, the Java importer lets you call Java classes on the app server side - I think what Ali is trying to do is integrate on the client side.
    If you want to add your own button then if you extend the standard Forms button in Java and then use this class name in the implementation class property then the Java for your button will be used instead of the standard Forms button. And since it has extended the basic Forms button it has all the standard button functionality.
    There is a white paper on OTN about this and we have created a new white paper which will be out in a couple of months (I think).
    Regards
    Grant Ronald<HR></BLOCKQUOTE>
    null

  • How to implement system monitoring(IT performance rep) in Solution Manager.

    Hi
    1.How to implement system monitoring(IT performance report) in Solution Manager?
    need to Monitroing *SAP Workload Areas -Total Database time,Total Avg. Response Time,ect..
    &SAP Operation System Areas -CPU Utilization* in SM workcenter is it possible?
    Please let me know how to configure ?
    2. Is it possible to monitor Solman system itself to get system monitoring--this is to test?
    regards
    Neni

    1.How to implement system monitoring(IT performance report) in Solution Manager?
    need to Monitroing *SAP Workload Areas -Total Database time,Total Avg. Response Time,ect..
    &SAP Operation System Areas -CPU Utilization* in SM workcenter is it possible?
    Please let me know how to configure ?
    Pls visit the roadmap of solution manager EHP1 -Operation with Solution manager
    you get many pdf and sim files for the same.
    https://websmp110.sap-ag.de/~sapidb/011000358700006940692005E.sim
    2. Is it possible to monitor Solman system itself to get system monitoring--this is to test?
    Yes it is possible
    visit the above section
    Hope solves prb
    Regards
    Prakhar

  • How does the ADF support romote call method between two managed server ?

    How does the ADF support romote call method between two managed server ?

    You would usually use this as a WebService through the WSDL that is exposed.
    JDeveloper can help you create a Java Proxy to call the Web service if you point it to the WSDL file that was generated for your AM.
    Some other samples here:
    http://www.connotea.org/user/jdeveloper/tag/Service%20Interface

  • Problem: Deploy a web app from a managed server - Can someone answer:  Is this a bug?!

    We're running 6.0sp2 on both AIX and RedHat. Deploying or redeploying
    a web app to the managed server fails, works fine on the Admin server.
    War's work fine in the 'applications' dir. The browser fails with a
    404 on the managed server, with the following error in the log:
    ####<Aug 9, 2001 4:58:45 PM GMT> <Error> <J2EE> <szuinet5> <ect2>
    <ExecuteThread: '11'
    for queue: 'default'> <system> <> <160001> <Error deploying application
    DefaultWebApp
    ect2: Cannot deploy WebAppServletContext(4320491,DefaultWebAppect2) on
    ect2 because
    WebAppServletContext(2930053,DefaultWebApp_ect2) is already registered
    for path >
    Are we missing the point here? Or, is this a known bug? Also, we are
    not in a position to jump onto v6.1 at this time.
    Thanks in advance.

    Hi,
    Yes..it's a bug. I had the same problem and it has been reported to support
    but no indication if it's fixed.
    Rgds,
    E-Wan
    ppower wrote:
    We're running 6.0sp2 on both AIX and RedHat. Deploying or redeploying
    a web app to the managed server fails, works fine on the Admin server.
    War's work fine in the 'applications' dir. The browser fails with a
    404 on the managed server, with the following error in the log:
    ####<Aug 9, 2001 4:58:45 PM GMT> <Error> <J2EE> <szuinet5> <ect2>
    <ExecuteThread: '11'
    for queue: 'default'> <system> <> <160001> <Error deploying application
    DefaultWebApp
    ect2: Cannot deploy WebAppServletContext(4320491,DefaultWebAppect2) on
    ect2 because
    WebAppServletContext(2930053,DefaultWebApp_ect2) is already registered
    for path >
    Are we missing the point here? Or, is this a known bug? Also, we are
    not in a position to jump onto v6.1 at this time.
    Thanks in advance.

  • How to stop a singleton class being clonable ?

    Do we have any way to stop clone method being invoked on a singleton class.
    One way I guess is to implement clone method and throw an exception inside the method.

    jwenting wrote:
    georgemc wrote:
    Why bother, though? Don't you trust your fellow developers not to do stupid things?why should I trust them to not do stupid things when I don't even trust myself to not do stupid things? >:=)Because trusting them not to do stupid things would actually be a stupid thing :)

  • How to implement a java class

    dear friends
    i use forms6i server and oracle 9i server edition,under windows 2000 server
    i try to implement a java class for a bean area. i do the following :
    from the property palette i write the class name in implementaion class property . the class name is 'arc.class' and it is located in <oracle_home>/forms60/java
    but the fellowing error appears
    frm-13008 cannot find javabean with name 'arc.class'
    would any one help please

    Dear Grant Ronald
    thank you very much for helping me . now i undersatand how to implement a class. but i have another question ,and i wish you ccould help me .
    i try to import a java class, i do the following:
    From the program menue i choose Import Java Class
    but the following error appears
    (pde-uji001 faild to create JVM)
    by the way i use forms6i server and oracle 9i server under windows 2000 server
    thanks in advance
    tarek

  • How to implement secure Licencing for Java Apps?

    Hi
    I'm already thinking some months about this topic. I serached the web, some books and magazines, i asked quite a lot of people - but in the end, there seems to be no really satisfying answer.
    My main question is: what can i do to protect the software i wrote? The problem is, where ever i start, i end with open questions.....
    I may start delivering a custom licence key with my software that contains information i.e. about who may run it and for how long. To check integrity i sign the licences key (with a digest) and ckeck the integrity in the application. Like this, i could make sure, that the software runs only with a valid licence.
    But two new problem araise - if the licence key is given to the web, everyone will be able to run the software. Second, i have to implement a methode to check the digest, so i have to deliver the key with the software and like this, the key could just be used to generate new licence files. Third, i hav to protect my code, since anyone could recompile it, he could check the algorithms i use to check the digest and even worse, he just could disable the codeblock that checks the licence.
    So i use an obfuscator to scramble my code, and to get the most out of this technique, i use a controlflow obfuscator. This adds some security, but still the code can be decompiled but wouldn't be too easy to understand. For making it even a little bit harder to read, i will "distribute" the licence digest check over some different classes.
    But still the first two problems remain. So i think about encrypting the licence file. To make that secure, i would use a public/private key encryption since if i use a secret key encryption i would have to deliver the key with the software and anyone could use it to generate new encrypted licene files. The problem with the public/private key is, that i should deliver a public key with the software that is only capable of decrypting, but not of encrypting. Like this, i can implement a decryption methode in the software that can decrypt the licence file and read all requiered licence data but the user is not able to generate a new licence file because he has the read-only key. Obvisouly there is no such private/public key technique that allows one key to be decrypt only and the other to be encrypt and decrypt (or at least encrypt only). Algorithms like PGP have a public key that allows encryption only and a private key that allows decryption only.
    I could go on presenting some more ideas i found to "protect" software/licence but the all come to the same point where they leave a lot of other open questions.
    I wonder what you all out there do to protect your software, what kind of technique you use for licencing implementation. I would be very glad to read what problem you face reagarding this topics and maybe how you solved it or what your conclusion was.
    Greetings
    josh

    >
    yes, absolutely. That's the point. Try to make it hard
    to get the software some other way. So it's easer to
    get the software by buying it.
    Nope.
    - There are those who steal it just to steal it. They don't use it.
    - There are those who steal it because the price is too extreme. If your income for the year is measured as only several thousand dollars you are not going to be able to buy a package that costs a thousand dollars or more.
    - There are those who steal it because the preceived benifit is less than the cost. For instance, at least in the past, MS software cost at least three times as much in some european companies compared to the exchange rate.
    - Finally there are those who steal simply because they don't want to pay for it.
    As far as I am concerned the last category is the only relevant one. And that is far smaller than any software theft estimates that the software industry regularly claims.
    >
    >>
    Here is an example of someone who thinks that their
    work is good enough and valuable enough to stand on
    its own...http://www.fileviewer.com/.
    And I liked it enough that at one company I hadthem
    purchase a site license. And I like it enough thatI
    still remember the company five years after thelast
    time I needed the product.that's fine and it would be very nice if everybody
    would be like you. But that's not the case and you
    even may not be sure if not someone in that company
    took a copy of the software and the licence and now is
    using it for free are even gave it in the "public
    domain". Woulnd't that be sad if the company would
    have to close down someday because just a few people
    are paying for it. Even if it is such a smart
    product?There was a clothing chain that closed down because they claimed that, even after installing anti-theft devices, they were still losing too much money from shop lifters.
    If that is the case why do all of the other companies still exist?
    If your product is good then people will buy it. The successes for that are abundant. The only success stories for copy protection schemes are for the copies that sell those schemes.
    >
    i wonder if you close your door when you leava your
    appartment. I mean, what's wrong with protecting a
    code? It's just the same as protecting the money you
    earn, the furnish in your appartment, ...
    Sorry, when I buy a product then I expect to be able to use it.
    With your analogy I would have to use a code that you provided everytime I wanted to get into and out of my apartment.
    So for any comments, ideas, ... on how to addsome
    more protection i'm very thankfull.You search for "obfuscator".yes, as i wrote in the first posting, i know about
    obfuscator, i'm using it, but it's just very poor
    protection. That's why I'm looking for a smart concept
    to gain a little bit more protection.And if you search for that term in these forums, and read the lengthy posts, you might find some ideas. Which is why I suggested it. (And you might understand why the alternatives are not used.)

  • How to implement custom Model Class in Oracle ADF?

    I am using Oracle ADF for one of my project and i am using Query component of ADF. For given tables the query component creates view objects and maps the relations. ADF uses its own custom model class for this component and it should understand the DB tables. But for my project i have no access to database. All i can do is pass a string or object/query to the existing (custom) Java class/object, and this model class formulates query and queries the database and returns the value to my Java class. I have to display these results using ADF to the front end. Is There a way to achieve this? Can i replace/override the existing Model class of ADF. If so how?
    Thanks in advance for your help.

    Hi, there:
    Best thing to do is to start with the default login.html page, and then modify it. The login screen is fairly complex and it's easy to just miss a JS function you need to call. To get to default page, you would need to do one deploy (to simulator or whatever), and then look for login.html page in the temporary Xcode or Android project generated from the deployment. It should be under the "deploy" directory in your JDev workspace.
    You can also see all the framework JS files and CSS files that way as well.
    We have had customers implementing custom login screen so we know it can work, but they all had to start with the default login screen and then modify it.
    Thanks,
    Joe Huang

  • How to implement this multi-langual APEX apps

    My requirements are:
    - login page has a dropdown of two languages: English (en-us) and French (fr)
    - page is refreshed when dropdown value has changed.
    - language is selected at login page, and this language setting cannot changed during session.
    - Use cookie to store the selected language, and this language is selected once the login page is launched next time.
    Implementation:
    Globalization Settings
    - primary lang = en-us
    - Application lang derived Form = item preference
    - do the translation in XLIFF files
    Login Page
    - create a SELECT LIST with name "FSP_LANGUAGE_PREFERENCE", list of value definition "STATIC:English;en-us,français;fr"
    - After Submit
    owa_util.mime_header('text/html', FALSE);
    owa_cookie.send(name => 'LANG', value=> :FSP_LANGUAGE_PREFERENCE, expires => sysdate + 30);
    - Before Header
    l_cookie := owa_cookie.get('LANG');
    l_value := l_cookie.vals(1);
    :FSP_LANGUAGE_PREFERENCE := l_value;
    Problems:
    When the cookie is stored with value "fr", the droplist is "francais" but the page is not in French,. Also, I don't know how to set the refresh the page when dropdown value is changed.
    Any suggestion ?

    hello
    About Refresh of the page when the value is selected:
    You need to change the type of select list to select list with submit/redirect and put also a Branch in the page so the app could know where to go after submit/redirect.
    About the cookie problem:
    I think that the setting of the value on the page doesn't make this value is set in app.
    After setting this value to any field (TEXT or LOV) you need to submit the page so the value will stick.
    I remember having the same problem but didn't solved it. :/
    And also I don't know if this matters but it's faster:
    l_cookie := owa_cookie.get('LANG');
    :FSP_LANGUAGE_PREFERENCE := l_cookie.vals(1);
    regards
    piotr

  • How to implement a singleton model in a Flex project

    After too much reading, I would like to use a singleton model in my Flex application to hold global variables.  What I cannot determine, however, is how to do this.  Is there a good tutorial/example available that could walk me through this for a Flex project?
    Thanks!

    Here's simple example code:
    package examples
       public class Singleton
          static public const instance:Singleton = new Singleton();
          // private constructors not supported
          public Singleton()
             if( _instance )
                throw new Error( "Singleton instance already exists." );
    Let me know if that helps...
    Ben Edwards

  • How to implement the abstract classes MessageDigest and Signature?

    Hi all,
    I've recently started working on JCDK 2.2.1.
    I have a problem to share and get suggestions from you!
    My aim is to implement ECDSA on Java card
    I have seen the Javacard API and tried to program using the classes
    MessageDigest and Signature. They are abstract classes and except the
    Method getInstance in them, the rest of all methods are declared abstract.
    Does that mean we have to give definition for them or else can we use
    them as they are?
    I tried giving some definitions, but to my surprise there's no such
    initiation of any variable to the algorithm we provide in the method
    "getInstance"! Then, it's not possible to give defn,. for other
    methods like getAlgorithm, reset, etc. How can we resolve this ?
    Any ideas?
    Regards,
    Johnbuchk

    try this...
    http://developer.sonyericsson.com/site/global/techsupport/tipstrickscode/java/p_java_0501.jsp
    hope it can help u

  • How to implement your own class.......I don't have a clue, please help!

    I'm new with Java and am so confused! I need help with the following exercise.
    Implement a class Employee. An employee has a name (a string) and a salary (a double). Write a default constructor, a constructor with two parameters (name and salary), and methods to return the name and salary. Write a program that tests your class. How do I do this?
    I can't figure out how to do this!!!!! Please show me an example!

    public class Employee {
      private String name;
      private double salary;
      public static void main(String[] args) {
        Employee employee = new Employee("Max Just", 64000);
        System.out.println(employee.getName() + "\nsalary: " + employee.getSalary());
      public Employee() {
        name = null;
        salary = null;
      public Employee(String name, double salary) {
        this.name = name;
        this.salary = salary;
      public String getName() {
        return name;
      public double getSalary {
        return salary;

  • How to implement the String class "split()" method (JDK1.4) in JDK 1.3

    is it possible , with some code, to implement the split() method of the String class......which is added in JDK1.4 ..... in JDK1.3
    would be helpful if anyone could suggest some code for this...

    Here it is
    public static String[] split(String source, char separ){
    answer=new Vector();
    int position=-1, newPosition;
    while ((newPosition=source.indexOf(separ,position+1))>=0){
    answer.add(source.subString(position+1,newPosition));
    position=newPosition;
    } //while
    answer.add(source.subString(position+1,source.length-1);
    return (String[])(answer.toArray());
    } //split

  • How to implement a java class in javafx?

    public interface WarningEvent {
        public void warningHandler ();
    function test ():Void {
            var warningEvent:WarningEvent = new WarningEvent() {
                public void warnHandler(){
        }I am trying to implement java method inside javafx, but without luck. I also tried override with javafx syntax, but still cannot get it. Any one could help on this?
    Thanks.

    1) Get rid of the keyword new
    2) Get rid of braces ()
    3) For the function declaration, use the JavaFX syntax, not the Java syntax!
    function test ():Void {
            var warningEvent:WarningEvent = WarningEvent {
                override public warnHandler():Void {
    }Your class need to have a default constructor (the one without any argument) to be able to do this (and in this case it works because you have an interface instead).

Maybe you are looking for