Singleton's in Mutliple Programs

My basic question is, if in my program I create a singleton class, but I run my program multiple times, do the the programs share the same class, or each make their own? I ask because I feel like I've seen both behavior, but can't tell what the difference was. Heres what I saw:
1. I wrote a class which uses com.sun.tools.javadoc.Main.execute() to read javadoc info and relay it back to my program. The class called SmartDoclet was a singleton class, as well as a Doclet. So I would call execute() giving SmartDoclet in as the custom Doclet class, javadoc would run my class, which would then communicate back to my "main" program via the singleton object and pass the RootDoc object which was created. Worked perfectly, which makes me think singleton's are shared across all programs.
2. But at the same time, I've written GUI programs where the top-level JFrame was a singleton so that I had easy access to common commands, reading properties, etc... and I've tried running multiple instances of the program and it works fine (i.e. multiple JFrame's).
So I guess what I dont understand is whats the difference between these two scenarios. What makes #1 not "step out" of the program, like just running the same program from the command line twice would do. Any help appreciated!

Is the danger that someone might make the Singleton
cloneable really a the most important reason to make a
Singleton non-extensible? I think not.It IS a good reason if cloning or subclassing it means
you can end up with more than one in the same JVM. If
you really implemented Singleton because "There Can
Only BE One", I'd say prohibiting subclassing and
cloning might be important.
I gotta go with the OP on this. That comment is abit queer.
I gotta go with the definition of Singleton on this
and disagree. It's not like it's that difficult.
Don't implement Cloneable or Serializable and make
the constructors private. Done. What's the
problem?
At some point it is just too much.
Are you going to implement a security manager as well? Because unless you do I can create JNI method and create a new object as well.
If they don't understand that the singleton is a singleton then are you going to assume that that is the only problem that they are having?
When I program I make assumptions about those that I work with and those that will come after me. I like to think that they have a minimal level of intelligent. They might not write the best code all the time but they do understand most of the ideas. And given that singleton the most used and probably easiest pattern to understand is it really necessary to be so protective?

Similar Messages

  • Issues About Subclassing Singleton

    Need some feedback whether my thinking is true. The issue is on what to do when I need to extend a singleton class.
    For a typical singleton like following:
    public class SingletonRoot{
       private sitatic SingletonRoot instance=null;
       protected void SingletonRoot();
       public static SingletonRoot getInstance() {
          if (instance==null)
             instance=new SingletonRoot();
          return instance;
       public void otherMethods(){}
    }Because I need to extend the class so to override otherMethods(), I will extend it:
    public class SingletonSub extends SingletonRoot {
    }In this subclass, I will not not declare another private static variable of instance to hide the one in the super class. I think this is for sure. Then the question is whether I need to override the getInstance(). If I do not override it, the first time I call it like SingletonSub.getInstance() will cause an instance of SingletonRoot instantiated. The subsequent calls to otherMethods() will always be the version in the base class, right?
    So, I will have to override it with following?
    public class SingletonSub extends SingletonRoot {
       private void SingletonSub();
       public static SingletonRoot getInstance() {
          if (instance==null)
             instance=new SingletonSub();
          return instance;
       public void otherMethods(){}
    }Is this right?
    But we know that we can not override static methods. So, my writing above is hiding the getInstance() in the base class. Then, depending on which class the client class will use as the qualifier of the method to call it, it will have different effects?

    Thanks for all the answers. Let me elaborate more below:
    To address those from DrClap: if I create another static variable instance in the SingletonSub class, it means that I will have one object for SingletonSub and one object for SingletonRoot. This is caused by this new static variable of instance in sub will hide the one in root, right? If I keep it as-is, there should be only one object for both classes.
    If I choose extending the root one with a new static variable of instance, it means that I like to keep all existing calls to the other non-static methods in the root one still calling the existing methods and only new reference or calls to the methods with the new SingletonSub instance will go to the sub one's overriden methods. For that purpose, I do need to have two separate instances for the two classes. Old code will keep using old methods and new code will use the new overriden methods (non-static other methods).
    But with my current code, there can only be one object for both classes. Depending on who is the first call to the getInstance(), the instance will be initialized to either SingletonRoot or SingletonSub. Then depending on which class it is initialized to, ALL the calls to those non-static overriden methods can be either the old one in the root or the new one in sub. But for the whole program, they will consistently call the same methods and there will be no case of calling old methods with old code referring to SingletonRoot and calling to new overriden methods for new code referring to SingletonSub.
    My needs are like following: there is a singleton class in this program and there are quite some calls related to this class. The class has quite a few non-static methods dealing with some business logics. Most methods are fine and we will keep as-is. But a couple of those non-static methods do not really fit our business logics. (Sorry, in my original example, I used otherMethods() to stand for all other non-static methods for business logics both fine or not fine. From now on, I will use otherMethod1() for all fine and otherMethod2() for all those need correction).
    So, we like to make minimum changes so that all calls to those otherMethod2() will be updated with new logics. If we had the source code of the SingletonRoot, we can simply go to those otherMethod2() to change all the logics. But even if we had the source code, better way might be to keep it as-is in case others may need those methods in that way in the future. So, I think a better way is to extend it with SingletonSub and override otherMethod2() in the sub-class. In this way, by just making this extension, we have made all existing calls to those otherMethod2() going to the overriden methods in the sub-class without touch any existing code any where. But I just realized when answering your question that if I do not make sure I have a call to SingletonSub.getInstance() before any other similar attempts against SingletonRoot, nothing will be pointing to the overriden methods in the sub-class. Basically, I am trying to use polymophism to achieve the changes without touching any existing code while only adding one new sub class extending the singleton class.
    I think even if I had the source code of the SingletonRoot, this might be better way to do it since you do not need to touch original code. If I do not do inheritance, how could I make changes so that the program will follow the new business logics in the otherMethod2() instead of those in the old otherMethod2() in the old singleton class. At the same time, any calls to otherMethod1() should remain unchanged. But having to make sure calling SingletonSub.getInstance() has to be the very first call to avoid uncertain instantiation might not be intuitive to other developers in the future when taking over the program. Any good solution for that?

  • ESS Payslip Functionality

    Hello Community,
    Please assist a customer on the following questions:
    A) On ESS Paylist there is the link "Show Overview". When clicking on the link it will expand and provide a list
    with previous remuneration statements. Is it possible that this link/list is shown in expanded status per default(in standard this link/list is collapsed)?
    B) Is it possible to pick the form depending on the period that is being printed?
    Thank you all.

    Mauricio Ghem wrote:
    > Hello Community,
    >
    > Please assist a customer on the following questions:
    >
    > A) On ESS Paylist there is the link "Show Overview". When clicking on the link it will expand and provide a list
    > with previous remuneration statements. Is it possible that this link/list is shown in expanded status per default(in standard this link/list is collapsed)?
    >
    > B) Is it possible to pick the form depending on the period that is being printed?
    >
    > Thank you all.
    ad B.)
    Yes it is possible. For the solution you need two things.
    (Implicit) Enhancement to class CL_HRXSS_REM, Method L_SET_CURRENT_PAYSLIP
    ENHANCEMENT 1  ZPESS_ENH_REM_VDATE.    "active version
    * INS ABNMK190510
      " Der aktuelle Gehaltsnachweis (Index) ist für Auswertung in
      " Merkmal HRFOR zu sichern
      data lo_rem_vdate type ref to zp_cl_ess_rem_vdate_api.
      lo_rem_vdate = zp_cl_ess_rem_vdate_api=>get_instance( ).
      lo_rem_vdate->set_current_period_indx( a_frontend_index ).
    ENDENHANCEMENT.
    This implementation just stores the index of the current selected period in a attribute of my own class (singleton).
    Using a program in feature HRFOR iinstead of the static HRForms return parameter
    *& Report  ZPA_PAYSLIP_HRFOR
    *& Report für das Merkmal HRFOR (Gehalstnachweis)
    report  zpa_payslip_hrfor.
    *&      Form  EXT_CALL_F
    *       text
    *  -->  NAMEN        text
    *  -->  STATUS       text
    *  -->  PME95        PME95
    *  <-->  BACK        text
    form ext_call_f using namen back status pmehf structure pmehf.
      " INS ABSMK190510
      data lo_rem_vdate type ref to zp_cl_ess_rem_vdate_api.
      data lv_hrform type hrf_name.
      " Handler ermittelt
      lo_rem_vdate = zp_cl_ess_rem_vdate_api=>get_instance( ).
      " Formular ermitteln
      lv_hrform = lo_rem_vdate->get_form( ).
      back = lv_hrform.
    endform.                    " EXT_CALL_F

  • Flash Player Won't Uninstall

    Thanks for taking the time to help me out.  Here's my problem:
    Flash is crashing mutliple programs on my computer (including one set of drivers).  I wanted to reinstall it, so I ran the 64-bit uninstaller found on Adobe's site.  When I went to verifyu that it has been uninstalled, I went to http://kb2.adobe.com/cps/155/tn_15507.html and I see:
    Okay, so apparently flash hasn't been uninstalled?  I checked C:\windows\system32\macromed\flash and there is only an installation log, which the most recent entry is:
    =O====== M/11.1.102.55 2012-02-14+22-08-59.491 ========
    0000 [I] 00000010 "C:\Users\Alex\Downloads\uninstall_flash_player_64bit (3).exe" -force 
    0001 [W] 00001036 Software\Macromedia\FlashPlayerPlugin/PlayerPath 2
    0002 [W] 00001036 Software\Macromedia\FlashPlayerActiveX/PlayerPath 2
    0003 [W] 00001036 Software\Macromedia\FlashPlayerActiveX/PlayerPath 2
    0004 [W] 00001018
    0005 [W] 00001037 Software\Macromedia\FlashPlayer\SafeVersions/ 2
    0006 [W] 00001037 SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Adobe Flash Player ActiveX/ 2
    0007 [W] 00001019
    0008 [W] 00001020
    0009 [W] 00001037 Software\Microsoft\Windows\CurrentVersion\RunOnce/FlashPlayerUpdate 2
    0010 [W] 00001037 Software\Macromedia\FlashPlayerActiveX/ 2
    0011 [W] 00001037 Software\Macromedia\FlashPlayer/FlashPlayerVersion 2
    0012 [W] 00001037 Software\Macromedia\FlashPlayer/SwfInstall 2
    0013 [W] 00001037 Software\Microsoft\Code Store Database\Distribution Units\{D27CDB6E-AE6D-11CF-96B8-444553540000}/ 2
    0014 [W] 00001021
    0015 [W] 00001036 Software\Macromedia\FlashPlayerActiveX/PlayerPath 2
    0016 [W] 00001036 Software\Macromedia\FlashPlayerPlugin/PlayerPath 2
    0017 [W] 00001037 Software\Microsoft\Windows\CurrentVersion\Control Panel\Extended Properties\System.ControlPanel.Category/C:\Windows\system32\FlashPlayerCPLApp.cpl 2
    0018 [W] 00001048
    0019 [I] 00000020 C:\Windows\system32\FlashPlayerCPLApp.cpl
    0020 [W] 00001036 Software\Macromedia\FlashPlayerPlugin/PlayerPath 2
    0021 [W] 00001018
    0022 [W] 00001036 SOFTWARE\MozillaPlugins\@adobe.com/FlashPlayer/ 2
    0023 [W] 00001037 SOFTWARE\MozillaPlugins\@adobe.com/FlashPlayer/ 2
    0024 [W] 00001037 SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Adobe Flash Player Plugin/ 2
    0025 [W] 00001019
    0026 [W] 00001020
    0027 [W] 00001037 Software\Microsoft\Windows\CurrentVersion\RunOnce/FlashPlayerUpdate 2
    0028 [W] 00001037 Software\Macromedia\FlashPlayerPlugin/ 2
    0029 [W] 00001037 Software\Macromedia\FlashPlayer/FlashPlayerVersion 2
    0030 [W] 00001037 Software\Macromedia\FlashPlayer/SwfInstall 2
    0031 [W] 00001021
    0032 [W] 00001036 Software\Macromedia\FlashPlayerActiveX/PlayerPath 2
    0033 [W] 00001036 Software\Macromedia\FlashPlayerPlugin/PlayerPath 2
    0034 [W] 00001037 Software\Microsoft\Windows\CurrentVersion\Control Panel\Extended Properties\System.ControlPanel.Category/C:\Windows\system32\FlashPlayerCPLApp.cpl 2
    0035 [W] 00001048
    0036 [I] 00000020 C:\Windows\system32\FlashPlayerCPLApp.cpl
    0037 [W] 00001036 Software\Opera Software/Last CommandLine 2
    0038 [W] 00001036 Software\Opera Software/Last CommandLine 2
    0039 [W] 00001036 Software\Opera Software/Plugin Path 2
    0040 [W] 00001036 Software\Opera Software/Plugin Path 2
    0041 [I] 00000011 1
    =X====== M/11.1.102.55 2012-02-14+22-09-35.330 ========
    There are no other files located in the directory.  I tried looking up anything by adobe in the Windows uninstaller, but no flash player or related programs come up.  Can anyone shed some light on what's going on for me?  Thanks so much:
    Other Specs:
    Windows 7 64-bit Professional
    Default Browser: Chrome

    Hello,
    The issue here is that Chrome includes a built in version of Flash Player that it maintains and it updates.  You can verify you're using the latest version of Chrome by going to it's "About Google Chrome" menu. 
    It does appear that you've successfully uninstalled the other versions (used for Internet Explorer, Firefox, Opera, etc.)
    What kind of crashes are you getting?
    Chris

  • Need some advise

    Hi All,
    I need some advise from you JAVA gurus. Here is the situation:
    Our Java development team developed an application running on Weblogic 8.1 SP3. The application is contained in the ear file....which is perfect. They now wanted to go live in about 3 months from now. We were discussing plans how to it live but running into a major show stopper.
    Our Linux/Unix weblogic support group do not support/ allow running any singleton java processes except whatever is running as weblogic instances.
    Application development has a requirement to run these 5-7 singleton small little java program (currently i do not know exactly what these small little java processes does).
    We have proposed that the application team should own these processes and they have to run it outside of the BEA weblogic servers (i.e these singleton processes are not allowed to run on our common Unix machines running WLS8.1 sp3).
    We have only ONE option:
    1) Run these small little singleton java processes somewhere else that will be owned by application team.
    Questions:
    1) What are the problems that may arise if these singleton processes do not co-exist with where the application server runs (hosting the application ear file)?
    2) Is there any other ways of circumventing this problem (any other ways based on your expertise) ?
    3) Also, iam trying to understand these singleton processes, so what questions should i ask before i have a head to head discussions with the application team ?
    [any watch list??]
    Thanks for all your help.
    Take care.

    duffymo/others,
    I was initially confused with the term "singleton" ...what i meant to say was "stand along java processes". So, there is nothing singleton but this application has few stand alone java processes that the Linux/Unix team do NOT want to run where the weblogic managed instances are running.
    So, say my weblogic servers are running on Host A and Host B each having 3-3 each BEA weblogic managed instances CLUSTERED...then these stand alone java processes IS NOT ALLOWED to run there.
    I hope this time i am much clearer .... :)
    Iam sorry .... i was totally confused with this term called "singleton" as i incorrectly misinterpreted as stand alone java processes ....sorry about that again.

  • What software/functions do I need to establish the communication between my C++ program and an instrument having only RS-232 (Singleton Cyclic corrosion Chamber CCT-10).

    I have Borland C++ 5.0 with NI-DAQ 6.9 driver for PC-LPM-16PnP, and want to synchronize DAQ initialized from C++ with a certain state of a Singleton CCT-10.

    You will need to use the RS 232 port on the computer, not the PC-LPM-16PnP. Use whatever serial functions Borland C++ provides.

  • How do I create a program with multiple sessions?

    I need to allow multiple sessions with this program.
    I realize that it involves threading of some sort, but I'm pretty new to this area and am not sure how I should go about this.
    Here are the instructions:
    "�     Write an application that will create an online dictionary a data file will be supplied that contains a list of words and their meanings. The hash table will contain a key (the word in question) and a value (byte offset of the word meaning stored in a random access file). You will also provide methods for entering, searching and deleting words online. The program must allow for multiple sessions."
    I have most of this all done, and have a dictionaryBroker ready to write the add, delete and search methods.
    But what about the mutliple sessions?
    I'm thinking that my hashTable and RandomAccessFile classes are both going to have to be singleton.
    What I want is for multiple people to be able to run the program at the same time, but if one person adds or deletes a record, I want it to update instantly for everyone.
    But it also needs to run smoothly for everyone using it.
    Thanks for any help, I just need a little push in the right direction here to help get me going.

    Well here is the entire assignment:
    &#61607;     Write an interface for a hash table that satisfies the following criteria:
    The hash table will contain a key (String) and a value (Object)
    Allow for a specific load capacity, if the capacity is exceeded the table is rehashed. The rehash may be called independently
    Must allow for maintaining the hash table (adding modifying etc) the key will not be changed
    Must allow for retrieving information from the table
    Must allow addition using a Map object or one key, value pair at a time
    The addition using a Map and the rehash must be a two pass approach
    �     Implement the interface.
    �     Write a test routine to test all aspects of the interface. The test must calculate the efficiency of your hashing algorithm.
    �     Write an application that will create an online dictionary a data file will be supplied that contains a list of words and their meanings. The hash table will contain a key (the word in question) and a value (byte offset of the word meaning stored in a random access file). You will also provide methods for entering, searching and deleting words online. The program must allow for multiple sessions.
    Submission
    Submit your eclipse project or executable jar file through WebCT. An efficiency of 70% or better must be attained for the assignment to be graded.
    I'm in Canada, not the US.
    It says online dictionary, but I don't think we actually have to do that. I'm pretty sure I can just use a simple GUI to allow them access to the dictionary.
    So, I'm assuming that I just have to make sure that if multiple people are trying to access it at the same time it needs to update at the same time or something. The hashtable was the main part of the assignment so this part shouldn't be too large.

  • Java Program with Adapter / Facade Pattern

    Hey All:
    I'm very new to the Java language and have been given a fairly complicated (to me) program to do for a course I'm taking. The following is the scenario. I'll post code examples I have and any help will be greatly appreciated. Let me apologize ahead of time for all the code involved and say thank you in advance :).
    The program is the follow the following logic:
    Organizations A's Client (Org_A_Client.java) uses Organization A's interface (Org_A_Interface.java) but we want A's Client to also be able to use Organization B's services as well (Org_B_FileAuthorMgr.java, Org_B_FileDateMgr.java, Org_B_FileIOMgr.java).
    Now a portion of this program also involves validating an xml file to it's dtd, extracting information from that source xml file through the use of a XMLTransformation file, and applying the transformation to produce a targetxml file which is then validated against a target DTD. (I've done this portion as I have a much better understanding of XML).
    At this point we have been given the following java classes:
    Org_A_Client.java
    package project4;
    /* This class is the Organization A Client.
    It reads a source xml file as input and it invokes methods defined in the
    Org_A_Doc_Interface Interface on a class that implements that interface */
    import java.io.*;
    import java.util.Scanner;
    public class Org_A_Client {
         // Define a document object of type Org_A_Doc_Interface
         private Org_A_Doc_Interface document;
         // The Org_A_Client constructor
         public Org_A_Client() {
              // Instanciate the document object with a class that implements the
              // Org_A_Doc_Interface
              this.document = new Adapter();
         // The Main Method
         public static void main(String Args[]) {
              // Instanciate a Client Object
              Org_A_Client client = new Org_A_Client();
              // Create a string to store user input
              String inputFile = null;
              System.out.print("Input file name: ");
              // Read the Source xml file name provided as a command line argument
              Scanner scanner = new Scanner(System.in);
              inputFile = scanner.next();
              // Create a string to store user input
              String fileID = null;
              System.out.print("Input file ID: ");
              // Read the Source xml file name provided as a command line argument
              fileID = scanner.next();
              //Convert the String fileID to an integer value
              int intFileID = Integer.parseInt(fileID);
              if (inputFile != null && !inputFile.equals("")) {
                   // Create and empty string to store the source xml file
                   String file = "";
                   try {
                        // Open the file
                        FileInputStream fstream = new FileInputStream(inputFile);
                        // Convert our input stream to a
                        // BufferedReader
                        BufferedReader d = new BufferedReader(new InputStreamReader(
                                  fstream));
                        // Continue to read lines while
                        // there are still some left to read
                        String temp = "";
                        while ((temp = d.readLine()) != null) {
                             // Add file contents to a String
                             file = file + temp;
                        d.close();
                        // The Client Calls the archiveDoc Method on the Org_A_Document
                        // object
                        if (!file.equals("")) {
                             client.document.archiveDoc(file, intFileID);
                   } catch (Exception e) {
                        System.err.println("File input error");
              } else
                   System.out.println("Error: Invalid Input");
    Org_A_Doc_Interface.java
    package project4;
    /* This class is the Standard Organization A Document Interface.
    * It defines various methods that any XML document object
    * in Organization A should understand
    public interface Org_A_Doc_Interface {
         void archiveDoc(String XMLSourceDoc, int fileID);
         String getDoc(int fileID);
         String getDocDate(int fileID);
         void setDocDate(String date, int fileID);
         String[] getDocAuthors(int fileID);
         void setDocAuthor(String authorname, int position, int fileID);
    Org_B_FileAuthorMgr.java
    package project4;
    public class Org_B_FileAuthorMgr {
         // This function returns the list of file authors for the file that matches
         // the given fileID. For the purpose of the assignment we have not
         // provided any implementation
         public String[] getFileAuthors(String fileID) {
              // Since we do not have any implementation, we just return a
              // null String array of size 2
              return new String[2];
         // This function sets the authorname at a given position for the file that
         // matches the given fileID.
         // For the purpose of the assignment we have not provided any
         // implementation
         public void setFileAuthor(String authorname, int position, String fileID) {
    Org_B_FileDateMgr.java
    package project4;
    public class Org_B_FileDateMgr {
         // This function returns the creation date for the file that matches
         // the given fileID. For the puprposes of the assignment we have not
         // provided any implementation but only return a date string.
         String getFileDate(String fileID) {
              return "1st Nov 2007";
         // This function sets the creation datefor the file that
         // matches the given fileID.
         // For the puprposes of the assignment we have not provided any
         // implementation
         void setFileDate(String date, String fileID) {
    Org_B_FileIOMgr.java
    package project4;
    import java.io.*;
    public class Org_B_FileIOMgr {
         // This class variable stores the file location for all files
         private String fileLocation;
         // This function stores the given String of XMLTargetFile at the
         // fileLocation which is set using the setFileLocation method
         boolean storeFile(String XMLTargetFile, String fileID) {
              if (this.fileLocation != null) {
                   FileOutputStream out; // declare a file output object
                   PrintStream p; // declare a print stream object
                   try {
                        // Create a new file output stream
                        // connected to "myfile.txt"
                        out = new FileOutputStream(fileLocation);
                        // Connect print stream to the output stream
                        p = new PrintStream(out);
                        p.println(XMLTargetFile);
                        p.close();
                        System.out.println("MSG from Org_B_FileIOMgr: Target File Successfully Saved with ID " + fileID);
                   } catch (Exception e) {
                        System.err.println("Error writing to file");
                        return false;
                   return true;
              System.out.println("MSG from Org_B_FileIOMgr: Please set the File Location before storing a file");
              return false;
         // This function sets the fileLocation where the file will be stored for
         // archive
         void setFileLocation(String fileLocation) {
              this.fileLocation = fileLocation;
         // This function retreives the file that matches the given fileID and
         // returns its contents as a string
         // Only for the puprposes of the assignment we have not provided any
         // implementation
         String retrieveFile(String fileID) {
              return "This is the retreived file";
    }Also, we've been given the following two classes which I believe are used to help with the xml transformation using SAX (I've done alot of research regarding parsing XML using SAX/DOM so I understand how it works, but I'm really struggling with the integration...)
    FileDetailsProvider.java
    package project4;
    /* This is the FileDetailsProvider Class which implements the Singleton design pattern.
    The class can be used in the following manner:
         // Declare a object of the class type
            FileDetailsProvider fp;
            // Get the single instance of this class by calling the getInstance static method
            fp= FileDetailsProvider.getInstance();
            // Initialize the class with providing it the file name of our configuration XML file
              fp.loadConfigFile("C:\\assignment4\\XMLTransformerConfig.xml");
    import java.io.File;
    import javax.xml.parsers.SAXParser;
    import javax.xml.parsers.SAXParserFactory;
    public class FileDetailsProvider {
         private InputHandler handler;
         private SAXParserFactory factory;
         private SAXParser saxParser;
         private final static FileDetailsProvider INSTANCE = new FileDetailsProvider();
         // Private constructor suppresses generation of a (public) default
         // constructor
         private FileDetailsProvider() {
              // Create the content handler
              handler = new InputHandler();
              // Use the default (non-validating) parser
              factory = SAXParserFactory.newInstance();
              // Validate the XML as it is parsed by the SAX Parser: only works
              // for dtd's
              factory.setValidating(true);
              try {
                   saxParser = factory.newSAXParser();
              } catch (Throwable t) {
                   t.printStackTrace();
                   System.exit(0);
         // This is the public static method that returns a single instance of the
         // class everytime it is invoked
         public static FileDetailsProvider getInstance() {
              return INSTANCE;
         // After instantiation this method needs to be called to load the XMLTransformer Configuration xml
         // file that includes the xsl file details needed
         // for our assignment
         public void loadConfigFile(String configFile) {
              try {
                   INSTANCE.saxParser.parse(new File(configFile), INSTANCE.handler);
              } catch (Throwable t) {
                   t.printStackTrace();
                   // Exceptions thrown if validation fails or file not found
                   System.out.println();
                   System.out.println("C:\\Documents and Settings\\Jig\\Desktop\\Project 4\\Project4\\Transform.xsl");
                   System.exit(0);
         // This method return the xsl file name
         public String getXslfileName() {
              return handler.getXslfileName();
         // This method returns the xsl file location
         public String getXslfileLocation() {
              return handler.getXslfileLocation();
    InputHandler.java
    package project4;
    /* This class is used by the FileDetailsProvider Class to read the XMLTranformerConfig xml
    * file using a SAX parser which is a event based parser
    import org.xml.sax.Attributes;
    import org.xml.sax.SAXException;
    import org.xml.sax.SAXParseException;
    import org.xml.sax.helpers.DefaultHandler;
    public class InputHandler extends DefaultHandler {
         private String xslfileName = "";
         private String xslfileLocation = "";
         int fileName = 0, fileLoc = 0, DTDUrl = 0;
         boolean endOfFile = false;
         public InputHandler() {
         // Start XML Document Event
         public void startDocument() throws SAXException {
              super.startDocument();
         // End XML Document Event
         public void endDocument() throws SAXException {
              super.endDocument();
              // display();
         public void display() {
              System.out.println(xslfileName);
              System.out.println(xslfileLocation);
         public void startElement(String uri, String localName, String qName,
                   Attributes attributes) throws SAXException {
              String eName = localName; // element name
              if ("".equals(eName))
                   eName = qName; // not namespace-aware
              if (eName.equals("File Name:")) {
                   fileName++;
              } else if (eName.equals("File Location:")) {
                   fileLoc++;
         public void endElement(String uri, String localName, String qName)
                   throws SAXException {
              String eName = localName; // element name
              if ("".equals(eName))
                   eName = qName; // not namespace-aware
         public void characters(char ch[], int start, int length)
                   throws SAXException {
              String str = new String(ch, start, length);
              // Getting the Transform File Location
              if (fileLoc == 1 && xslfileLocation.equals("C:\\Documents and Settings\\Jig\\Desktop\\Project 4\\Project4\\")) {
                   xslfileLocation = str;
              // Getting the Transform File Name
              if (fileName == 1 && xslfileName.equals("Transform.xsl")) {
                   xslfileName = str;
         public void processingInstruction(String target, String data)
                   throws SAXException {
         // treat validation errors as fatal
         public void error(SAXParseException e) throws SAXParseException {
              throw e;
         // This method return the xsl file name
         public String getXslfileName() {
              return xslfileName;
         // This method returns the xsl file location
         public String getXslfileLocation() {
              return xslfileLocation;
    }I need to do the following:
    1. Create an adapter class and a facade class that allows Client A through the use of Organization's A interface to to use Organization B's services.
    2. Validate the Source XML against its DTD
    3. Extract information regarding the XSL file from the given XMLTransformerConfig xml file
    4. Apply the XSL Transformation to the source XML file to produce the target XML
    5. Validate the Target XML against its DTD
    Now I'm not asking for a free handout with this program completed as I really want to learn how to do a program like this, but I really don't have ANY prior java experience other than creating basic classes and methods. I don't know how to bring the whole program together in order to make it all work, so any guidance for making this work would be greatly appreciated.
    I've researched over 100 links on the web and found alot of useful information on adapter patterns with java and facade patterns, as well as SAX/DOM examples for parsing xml documents and validation of the DTD, but I can't find anything that ties this all together. Your help will be saving my grade...I hope :). Thanks so much for reading this.

    No one has anything to add for working on this project? I could really use some help, especially for creating the code for the adapter/facade pattern classes.

  • How to execute dos command in Java program?

    In Perl, it has System(command) to call dos command.
    Does java have this thing?
    or any other way to execute dos command in java program?
    Because i must call javacto compile a file when the user inputed a java file name.

    Look in the Runtime class, it is implemented using the Singleton design pattern so you have to use the static method getRuntime to get its only instance, on that instance you can invoke methods like
    exec(String command) that will execute that command in a dos shell.
    Regards,
    Gerrit.

  • 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.

  • (retain) properties in the singleton class

    Hi,
    What happens with the properties declared with (retain) in the singleton class:
    MyClass *foo;
    @property (nonatomic, retain) MyClass *foo;
    I am using a singleton class as explained http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/CocoaFunda mentals/CocoaObjects/CocoaObjects.html#//apple_ref/doc/uid/TP40002974-CH4-SW32 which should NOT be released.
    I see no way to call
    [foo release].
    My guess is that these properties will be allocated once and persist though entire life of the singelton - which is not a leak.
    correct?

    leonbrag wrote:
    My guess is that these properties will be allocated once and persist though entire life of the singelton - which is not a leak.
    correct?
    Yes. Of course, there are still ways to get rid of singletons if you really want/had to. In some cases, you could have a singleton that allocated system resources that aren't automatically released when a program ends. There are ways to clean up such things if you run across them. Look at the "applicationWillTerminate:" notification, for example.

  • Singleton vs static - which is better?

    Of the two approaches -
    a class which can be used by accessing its ONLY instance(singleton) or a class which has a set of static methods which can be invoked on the class itself
    which is better and why? Or are these just two 'styles' of programming?
    I always get confused as to which way to go? I tend to prefer to have static methods on the class instead of a singleton.
    All insights/comments/ideas welcome.
    Thanks

    Well, there are a few questions you can ask - does the method cause any changes of state, or is it a pure function? If the latter, static is probably the way to go.
    The way you are talking, I gather that there is some state involved.
    Next question: does it make sense for there to be more than one of these per JVM? Not only in the way you currently envision it, but at all, anywhere. For example, consider the list of Strings that the String class keeps so it can consolidate memory and avoid duplication (see String.intern() ). That list makes sense to be static.
    On the other hand, the representation of the state of a board game should not be static, because someone could want to write a program which has multiple games within it - or you could within one game wish to have contingencies or undo-ability (essentially, it might not be as singleton as you think).
    Next, if you think the methods will ever need to be overridden, use a singleton, because static methods aren't, well, dynamic! (in case the singleton is a one-at-a-time singleton but it makes sense to have a change of identity over time).
    I have never written a true singleton - though often written classes which I did not PLAN on instantiating more than once.

  • Best method to trigger events in a constantly-running program?

    I need to have a particular Java application always running in the background on my Linux machine (like a daemon) (it's a singleton -- no two instances will run simultaneously). However, I need to be able to send "events" to this application from another program, where an event is as simple as a line of text that the application interprets as some action. These events will be invoked by a non-Java program, so it should be possible for them to be called by, for example, a shell script that is executed. What's the best way to do this? The only idea I could come up with is:
    The program writes the event to a file. The main Java application watches a particular file for changes -- when it encounters changes, it reads the file and takes the appropriate action.
    Anything more elegant than that?
    EDIT: Would it be better to have my main application listen on a particular port, and have the invoking application send the event information across that port?
    Edited by: Tony_R on Dec 6, 2009 10:12 PM

    Tony_R wrote:
    The program writes the event to a file. The main Java application watches a particular file for changes -- when it encounters changes, it reads the file and takes the appropriate action.
    Anything more elegant than that?See below.
    EDIT: Would it be better to have my main application listen on a particular port, and have the invoking application send the event information across that port?Yes, a local socket is usually the best solution. On Unix, it might be possible to use a (named) pipe, but sockets should work just fine and are the standard solution for this sort of thing.

  • Singleton in ABAP

    Hi,
    1) I have created a class with its instantiation set to private.
    2) Declared a static attribute 'instance' in the class with TYPE REF to same class.
    3) In the class constructor checked if instance is initial if it is then created an object.
    if instance initial.
        creat'e object instance.
    endif.
    4) Created a method get_instance which exports the 'instance' attribute of the class.
    I suppose this is fine for implementing the Singleton class.
    Created a sample program where I call get_instance of this class.
    Open two sessions of SE80 and execute this program in debug mode. I see that each program is executing the class constructor and instance is initial every time.
    If instance is initial in each execution (with two parllel executions) then what is the purpose of declaring it as static.
    Since its initial create object is executed every time in
    each execution. Then the instance is not unique and its not singleton.
    Can somebody explain signleton in ABAP. Why is it different from JAVA.
    Regards,
    Sesh

    Hi Sesh,
    Your class object exists per default once per session. As of release 6.40 you can create objects in the shared memory (with addition AREA HANDLE), thus session-independent! For that, you need to mark the class as shared-memory enabled. This should create a singleton as in Java.
    Best regards,
    Georg

  • Is abap thread safe? Some question in Singleton pattern in ABAP

    Hi Grus,
    I have a very basic question but really make me headache...
    Recently I am learning the design pattern in ABAP and as you know in JAVA there is a key word "Synchronized" to keep thread safe. But in ABAP, I didn't find any key words like that. So does that mean ABAP is always a single thread language? And I found that there is a way looks like "CALL FUNCTION Remotefunction STARTING NEW TASK Taskname DESTINATION dest" to make multi-thread works. As you can see it use the destination, so does that mean actually the function module is always executed in a remote system, and in every system, it is always single thread?
    Could you help me on the question? Thanks a lot, grus
    And here comes up to my mind another question...It's a little bit mad but I think it may works....What if I set every attribute and method as static in the singleton class...Since as you can see it is already a singleton so every attribute in it should be only one piece. So then I don't even need to implement a get_instance( ) method to return the instance. Just call "class_name=>some_method( )" directly then singleton is achieved...What do you think?
    BR,
    Steve

    Steve,
    I've the same question, few days ago I tried to use the singleton in ABAP. In Java programming is possible to use the same reference in two sessions or programs, sharing attributes, methods and all data, but I could not do in ABAP.
    In my test I created a program with one global class using the singleton pattern, so I expected that when I run my program and see the reference returned after the get_instance method it should be equal to the same program run in another session, but the ABAP will create a new reference and instantiate again.
    So I deduced that the only way to share it between sessions in ABAP is using the ABAP Shared Memory Objects.
    I can be wrong, but I think that ABAP use a thread by user session (Each window) and we can't change it.
    Best regards.

Maybe you are looking for