Why the singleton pattern used rather than static things?

class Single
    private Single() {}
    private void print() { System.out.println("Foo~"); }
    private static Single one = new Single();
    public static void print() { one.print(); }
class Stat
    public static void print() { System.out.println("Foo~"); }
}What's the different?? What is the benefit of the singleton one?

There is no practical difference - because, in fact, that is not the singleton pattern!
A singleton would look like:
class Singleton {
    private Singleton() {}
    public void print() { System.out.println("Foo~"); }
    private static Singleton instance = new Singleton();
    public static Singleton getInstance() { return instance; }
}The benefit of this pattern is, that your client code doesn't have to know that there is only one instance (getInstance could return another instance for every call) or of which actual type it is (getInstance could return an instance of any Subclass of Singleton).
See http://c2.com/cgi/wiki?SingletonPattern for more information on the pattern.

Similar Messages

  • Safari on my iPad 4 opens the latest page used rather than my home page. This is new ,after I updated to IOS 8.3.How do I get it back to what it was?

    Safari on my iPad 4 opens the latest page used rather than to my home page.
    This is new ,after I updated to IOS 8.3.How do I get it back to what it was?

    You're welcome. You're not alone. The change has left alot of people scratchiing their heads wondering why. Maybe if enough people leave feedback at the link below it will be changed.
    http://www.apple.com/feedback/

  • How we can limit the number of concurrent calls to a WCF service without use the Singleton pattern or without do the change in BizTalk Configuration file?

    How can we send only one message to a WCF service at a time? How we can limit the number of concurrent calls to a WCF service without use the Singleton pattern or without do the change in BizTalk Configuration file? Can we do it by Host throttling?

    Hi Pawan,
    You need to use WCF-Custom adapter and add the ServiceThrottlingBehavior service behavior to a WCF-Custom Locations.
    ServiceThrottlingBehavior.MaxConcurrentCalls - Gets or sets a value that specifies the maximum number of messages actively processing across a ServiceHost. The MaxConcurrentCalls property specifies the maximum number of messages actively
    processing across a ServiceHost object. Each channel can have one pending message that does not count against the value of MaxConcurrentCalls until WCF begins to process it.
    Follow MSDN-
    http://msdn.microsoft.com/en-us/library/ee377035%28BTS.10%29.aspx
    http://msdn.microsoft.com/en-us/library/system.servicemodel.description.servicethrottlingbehavior.maxconcurrentcalls.aspx
    I hope this helps.
    Rachit
    If this answers your question please mark it accordingly. If this post is helpful, please vote as helpful by clicking the upward arrow mark next to my reply.

  • CS6 Camera Raw - I can now only crop using aspect ratio in the custom crop setting rather than being able to set the dims in cm and inches? anyone know how to revert? ever since installing new mac operating system things have been strange!

    CS6 Camera Raw - I can now only crop using aspect ratio in the custom crop setting rather than being able to set the dims in cm and inches? anyone know how to revert? ever since installing new mac operating system things have been strange!

    Hi Kglad.
    I have looked at all of my settings both in Bridge and CS6 Photoshop regarding Camera Raw. I am at a loss how to set the crop tool in cm or inches as I once did - now the only option is to crop using ratios of 1:1 etc etc - This is infuriating as lots of my square crops I could set at 10" x 10'' specifically to print one to one to fit frame and mount size -
    Now if cropping using bloody aspect ratio of 1:1 (square) the actual dims of the crop are roughly 4.25 inches x 4.25 inches. this means I then have to open the whole image in photoshop in order to crop at the dims I have set! It was so much quicker in terms of batch cropping in camera raw being able to set dims in centimetres and inches but they have gone and mucked around with it, with the new bloody update! Unless you are an absolute genius and know how I can go back to having an option of CM, Inches and aspect ratio within the custom crop settings? (Please say you do)
    here is the new tutorial for CC -  my guess is they have scrapped the control we had over the custom crop settings
    Cropping Images In Adobe Camera Raw 8

  • When I click on a website in my reading list, why does top sites open rather than the site I've clicked on?

    When I click on a website in my Reader list in Safari, why does Top Sites open rather than the website I've clicked on?

    Go step by step and test.
    Reset Safari.
    Click Safari in the menu bar.
    From the drop down select "Reset Safari".
    Click "Reset".
    Delete Cookies
    Safari > Preferences > Privacy > Cookies and other website data:
    Click “Remove All Website Data”.
    Empty Caches
    Safari > Preference > Advanced
    Checkmark the box for "Show Develop menu in menu bar".
    Develop menu will appear in the Safari menu bar.
    Click Develop and select "Empty Caches" from the dropdown.
    Turn off Extensions if any, and launch Safari.
    Safari > Preferences > Extensions

  • Serializing a class that implements the Singleton pattern

    Hello,
    I am relatively new to Java and especially to serialization so the answer to this question might be obvious, but I could not make it work event though I have read the documentation and the article "Using XML Encoder" that was linked from the documentation.
    I have a class that implements the singleton pattern. It's definition is as follows:
    public class JCOption implements Serializable {
      private int x = 1;
      private static JCOption option = new JCOption();
      private JCOption() {}
      public static JCOption getOption() { return option; }
      public int getX() { return x; }
      public void setX(int x) { this.x = x; }
      public static void main(String args[]) throws IOException {
        JCOption opt = JCOption.getOption();
        opt.setX(10);
        XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(new FileOutputStream("Test.xml")));
        encoder.setPersistenceDelegate(opt.getClass(),  new JCOptionPersistenceDelegate());
        encoder.writeObject(opt);
        encoder.close();
    }Since this class does not fully comply to the JavaBeans conventions by not having a public no-argument constructor, I have create a class JCOptionPersistenceDelegate that extends the PersistenceDelegate. The implementation of the instantiate method is as follows:
      protected Expression instantiate(Object oldInstance, Encoder out) {
           Expression expression = new Expression(oldInstance, oldInstance.getClass(), "getOption", new Object[]{});
            return expression;
      }The problem is that the resulting XML file only contains the following lines:
        <java version="1.5.0_06" class="java.beans.XMLDecoder">
            <object class="JCOption" property="option"/>
        </java> so there is no trace of the property x.
    Thank you in advance for your answers.

    How about this:
    import java.beans.DefaultPersistenceDelegate;
    import java.beans.Encoder;
    import java.beans.Expression;
    import java.beans.Statement;
    import java.beans.XMLEncoder;
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    public class JCOption {
        private int x = 1;
        private static JCOption option = new JCOption();
        private JCOption() {}
        public static JCOption getOption() { return option; }
        public int getX() { return x; }
        public void setX(int x) { this.x = x; }
        public static void main(String args[]) throws IOException {
          JCOption opt = JCOption.getOption();
          opt.setX(10);
          ByteArrayOutputStream os = new ByteArrayOutputStream();
          XMLEncoder encoder = new XMLEncoder( os );
          encoder.setPersistenceDelegate( opt.getClass(), new JCOptionPersistenceDelegate() );
          encoder.writeObject(opt);
          encoder.close();
          System.out.println( os.toString() );
    class JCOptionPersistenceDelegate extends DefaultPersistenceDelegate {
        protected Expression instantiate(Object oldInstance, Encoder out) {
            return new Expression(
                    oldInstance,
                    oldInstance.getClass(),
                    "getOption",
                    new Object[]{} );
        protected void initialize( Class<?> type, Object oldInstance, Object newInstance, Encoder out ) {
            super.initialize( type, oldInstance, newInstance, out );
            JCOption q = (JCOption)oldInstance;
            out.writeStatement( new Statement( oldInstance, "setX", new Object[] { q.getX() } ) );
    }   Output:
    <?xml version="1.0" encoding="UTF-8"?>
    <java version="1.5.0_06" class="java.beans.XMLDecoder">
    <object class="JCOption" property="option">
      <void property="x">
       <int>10</int>
      </void>
    </object>
    </java>

  • WHY WE GO FOR SESSION RATHER THAN LSMW ?

    WHY WE GO FOR SESSION RATHER THAN LSMW  , AND I WANT TO KNWO THE DIFFERANCES BETWEEN THEM AND IN WICH CONDITIONS  SESSION AND LSMW ARE  MOST SUTED? THANKING U

    hi,
    In BDC ,we can run session as per our need, you can run in foreground ,background or even you can run on periodic wise ,where as in LSMW
    you cant run as your wish .
    BDC (Batch Data Communication) is a technology used for data transfer. it is meant for transferring data thru SAP transactions itself. when u use BDC for data transfer, the sequence of steps is the same as when u use standard sap transaction screens for data upload. the only difference is that u can use different options for foreground/backgrou nd processing.
    LSMW on the other hand is a tool that helps migrate data from a legacy system (non-sap system ) to SAP system. it offers u various options to use either batch input, direct input, BAPIs or idocs. it involves a series of some 17-18 steps to migrate data.
    BDC:
    Batch Data Communication (BDC) is the process of transferring data from one SAP System to another SAP system or from a non-SAP system to SAP System.
    Features :
    BDC is an automatic procedure.
    This method is used to transfer large amount of data that is available in electronic medium.
    BDC can be used primarily when installing the SAP system and when transferring data from a legacy system (external system).
    BDC uses normal transaction codes to transfer data.
    Types of BDC :
    CLASSICAL BATCH INPUT (Session Method)
    CALL TRANSACTION
    BATCH INPUT METHOD:
    This method is also called as ‘CLASSICAL METHOD’.
    Features:
    Asynchronous processing.
    Synchronous Processing in database update.
    Transfer data for more than one transaction.
    Batch input processing log will be generated.
    During processing, no transaction is started until the previous transaction has been written to the database.
    CALL TRANSACTION METHOD :
    This is another method to transfer data from the legacy system.
    Features:
    Synchronous processing. The system performs a database commit immediately before and after the CALL TRANSACTION USING statement.
    Updating the database can be either synchronous or asynchronous. The program specifies the update type.
    Transfer data for a single transaction.
    Transfers data for a sequence of dialog screens.
    No batch input processing log is generated.
    LSMW:
    The LSM Workbench is an R/3-based tool that supports You when transferring data from non-SAP systems ("Legacy Systems") to R/3 once or periodically.
    The tool supports conversion of data of the legacy system in a convenient way. The data can then be imported into the R/3 system via batch input, direct input, BAPIs or IDocs.
    Furthermore, the LSM Workbench provides a recording function that allows to generate a "data migration object" in an entry or change transaction.
    The main advantages of the LSM Workbench:
    • Part of R/3 and thus independent of individual platforms
    • A variety of technical possibilities of data conversion:
    • Data consistency due to standard import techniques:
    Batch input
    Direct input
    BAPIs (Business Application Programming Interfaces)
    IDocs (Intermediate Documents)
    The import technique to be used in an individual case depends on the business object.
    • Generation of the conversion program on the basis of defined rules
    • Clear interactive process guide
    • Interface for data in spreadsheet format
    Reward points if this helps you.
    Siva

  • Why the system is very slow than before

     I have two computers, One is desktop, another is laptop,but I met the problems about the performance for the two
    computers, from last Monday, two computers speed are very slow, after I checked the task manager, I found the service(ntoskrnl.exe) used the 60-70% CPU resource, but why the ntoskrnl.exe cause this? I also download the tools and analysised it, but it seems
    that no useful information,how to find the root cause?
    summary all the information as below
    1.Suddenly this problems happened
    2. I closed the AVP (Kaspersky antivirus software), but it seems no improved for the performance
    3. I have closed the Windows search service, but no change for this
    4\I use the maxthon and Firefox browse
    , all the same thing happened.
    you can download the Log file from http://1drv.ms/WwTBhU

    Hi,
    Any update in this thread?
    http://social.technet.microsoft.com/Forums/windows/en-US/ce42930b-f0f3-4df7-a621-d8f9d59109b4/why-the-system-is-very-slow-than-before?forum=w8itpronetworking
    Regards
    Yolanda Zhu
    TechNet Community Support

  • How to test with the standard Flash player, rather than debug player

    Folks,
    I am interested in running my flexunit 4 tests against the standard flash player, rather than the debug player that comes with the SDK.  Is this possible?
    BTW, I am working on Windows for now.
    I installed both the flash ActiveX control for IE, and the standard flash plugin for Firefox.  I then associated the SWF file extension with Firefox using the "Open With" dialog.  I had to choose a single program, and the browser appeared to be my only choice, as I could not find any sort of "FlashPlayer10.exe" to associate with.  I ran my ant script that calls <flexunit>, and it kind of works.  It launches Firefox, runs the tests, and the results get piped back, but Firefox is not shut down.  Yep, Firefox stays open after the tests complete.  I seem to recall that the debug flash player would close itself after being opened by <flexunit>.  I tried using IE, and the same result occurs: the browser is not shutdown after the tests complete.  This behavior makes for an unacceptable test setup, as eventually the system memory on the machine will be exhausted as more and more browsers are opened and not closed.
    Questions/options:
    1) Is there a standard flash player "executable" somewhere on my system that I can associate the SWF files with (that would hopefully shut itself down)?
    2) Second choice, is there a way to get the browser to close after <flexunit> completes?
    3) or am I stuck using the debug player?  I am concerned that testing management at my company might not like the fact that we are testing against a debug player, rather than the standard one that users will likely be using. If flexunit 4 CI only supports the debug player, is there something I can say to appease management?
    Thanks for any help...
    Trevor

    @trevorbutler - Here are my 2 cents, but the group may have a different perspectives for your questions.
    Currently, we suggest the use of the CIListener class as a FU4 listener for use when building your test SWF to run via the FU4 Ant task.  This class (http://opensource.adobe.com/svn/opensource/flexunit/branches/4.x/FlexUnit4CIListener/src/o rg/flexunit/listeners/CIListener.as) uses the fscommand() function to send a message to its host environment to exit (i.e. - fscommand("quit")).  This command is only recognized by the Flash projector and stand-alone players, which are thin wrappers around the Flash Player so that it may be executed as its own process in the OS.  Based on the setup you are describing, the behavior you're seeing should be expected since the browser is the host environment for the Flash Player.  When the browser recieves the resulting message of the fscommand("quit") call nothing will happen since the browser doesn't support this command.  If you use the Flash projector or stand-alone players however, they will exit when recieving the results of this command.  The projector/stand-alone players come in two flavors, release and debug.  Release will act very closely to the typical plugin installed in the web browser (e.g. - swallows errors, no debug support, etc) whereas debug will allow you to write log files to the system, show error messages, etc.  Currently the debug stand-alones are available on Windows, Mac, Linux and the release stand-alone is only available on Linux.
    To address your questions:
    1.  If you've installed the Flash Player browser plugin, there is no way that I know of to launch the player as its own process.  I've only had success using the projector/stand-alone player (http://www.adobe.com/support/flashplayer/downloads.html).
    2.  The Flash Player does have the ability to send javascript to the browser to ask it to close the current window, but most modern browser will prompt the user to confirm they'd like to close the window if its the only open window.  Additionally, taking this approach on Mac, the browser process would remain active until an explicit call is made to the host OS to shut down the browser process.  The Ant task could be enhanced to use the browser to launch the Flash Player, but that is not currently on our checklist of features to support.  If it's something you'd be interested in contributing, let me know and I can work with you on this.
    3.  For the time being the FlexUnit4 Ant task only supports the stand-alone Flash Player (and adl soon), which for Windows only comes in the debug flavor. The only thing I've run into with the stand-alone player is that ExternalInterface reports that its enabled, but since the host environment is not the browser, javascript calls made via this class will fail, consequently causing tests to fail.  I haven't tried anything with shared objects or flashvars but my assumption is that they should work correctly, but anything that depends on the browser has the potential not to.
    As far as your testing management goes, I would discuss with them the problem context FlexUnit4 hopes to solve.  The framework is intended to produce unit and integration tests.  Functional testing is not withing the scope of the library.  Although, it's technically feasible to write integration tests which will exercise components similarly to a functional test, tools such as FlexMonkey, Selenium Flex, QTP, etc are much better geared towards this problem domain.  Test recording and playback, using these tools, is typically done using the FP browser plugin and is much easier to use by most QA and testing staff.  At the end of the day, as we're testing our code using FlexUnit at a smaller granularity than that of which the user interacts with in our application.  To reliably test the applicaiton as the user would interact with it requires additional tooling and a different type of testing.
    Like I said, just my take, maybe some of the other guys can help as well.

  • Implementing the Singleton pattern

    Has anyone implemented the singleton pattern in Forte? A singleton is simply ensuring that there is one unique instance of a class. In other OO languages I would create a class method which would use a class variable to hold onto the unique instance. Since forte doesn't have either of these (class methods or variables), I'm not sure how to do it. I thought of using named objects, but it seems like a heavy implementation. Any ideas.

    An SO with its shared=TRUE and anchored=TRUE?
    Venkat J Kodumudi
    Price Waterhouse LLP
    Internet: [email protected]
    Internet2: [email protected]
    -----Original Message-----
    From: [email protected] [SMTP:[email protected]]
    Sent: Monday, February 02, 1998 1:09 PM
    To: Venkat Kodumudi
    Subject: Implementing the Singleton pattern
    To: [email protected] @ Internet
    cc:
    From: [email protected] @ Internet
    Date: 02/02/98 12:36:02 PM
    Subject: Implementing the Singleton pattern
    Has anyone implemented the singleton pattern in Forte? A singleton is
    simply
    ensuring that there is one unique instance of a class. In other OO
    languages I
    would create a class method which would use a class variable to hold
    onto the
    unique instance. Since forte doesn't have either of these (class
    methods or
    variables), I'm not sure how to do it. I thought of using named
    objects, but it
    seems like a heavy implementation. Any ideas.

  • Why is ios getting worse rather than better

    Why is ios getting worse rather than better?

    It is. Why wont complete my album actually complete my album and put the songs in the same folder. Why oh why have apple sent google packing, why is the maps app so rubbish just for a starter

  • In BAPI's why the structures are used in table parameters?

    Hello sir,
    what is BAPI sir? In BAPI's why the structures are used in table parameters?  table parameters they are using structures but not using any customized tables ? 
    regards
    rachu.

    Hello Rachu
    BAPIs provide RFC-enabled interfaces to SAP business objects (e.g. like customer, sales order, purchase order, etc.).
    A BAPI does basically the same like you would need to do calling the corresponding transaction (e.g. BAPI_SALESORDER_CREATE -> VA01).
    Since they are RFC-enabled they can be called from external systems.
    BAPIs represent an external interface for the outside world. Very often you will find within the BAPI that there is a mapping done to the (SAP-)internal structures at the beginning of the coding and vice versa at the end of the coding. Thus, you will (almost) never find any DB table name used as type of a BAPI TABLES parameter.
    Regards
      Uwe

  • Why the flashback log'size smaller than the archived log ?

    hi, all . why the flashback log'size smaller than the archived log ?

    Lonion wrote:
    hi, all . why the flashback log'size smaller than the archived log ?Both are different.
    Flash logs size depends on parameter DB_FLASHBACK_RETENTION_TARGET , how much you want to keep.
    Archive log files is dumped file of Online redo log files, It can be either size of Online redo log file size or less depending on online redo size when switch occurred.
    Some more information:-
    Flashback log files can be created only under the Flash Recovery Area (that must be configured before enabling the Flashback Database functionality). RVWR creates flashback log files into a directory named “FLASHBACK” under FRA. The size of every generated flashback log file is again under Oracle’s control. According to current Oracle environment – during normal database activity flashback log files have size of 8200192 bytes. It is very close value to the current redo log buffer size. The size of a generated flashback log file can differs during shutdown and startup database activities. Flashback log file sizes can differ during high intensive write activity as well.
    Source:- http://dba-blog.blogspot.in/2006/05/flashback-database-feature.html
    Edited by: CKPT on Jun 14, 2012 7:34 PM

  • Where can i set the download options on the iPod for SD rather than HD movies?

    where can i set the download options on the iPod for SD rather than HD movies?

    In the Summary pane for the iPod in iTunes.  Check the box that says Prefer standard definition videos

  • What's the advantage of using JSF than other MVC model

    What's the advantage of using JSF than other MVC model ?
    eg, Any advantage of using JSF than struts? What's their main difference?

    There is a good picture that shows that JSF brings new. You can find this picture on the page #9 of the "All about JavaServer Faces" by Kito Mann.
    URL:  http://www.cppsig.org/nycjava/All%20about%20Faces%20-%20NYPCUG%20-%2004-2004.pdfActually, you can search for "jsf vs struts" on this forum and find a lot of interesting material regarding to this topic.

Maybe you are looking for

  • Crystal Reports using DSO in BW: unable to display Text

    Hi, I have built a Crystal Report on top of DSO in BW System. I am able to display only the key for a field and the corresponding text is not available. So if there is a 0COMP_CODE key field, I am not able to get its description in Crystal Reports. W

  • Bug report: import image failure

    When I try to import images (formatted as either .gif or .jpg) some fail to load and a blank outline of the appropriate dimensions appears. Images that fail to appear have been set to grayscale and/or RGB, and have a file size less than 200 KB.

  • Cannot find BI Apps Product Guides for 7.9.6.4

    Does anyone know where I can find the BI Apps Product Guides for 7.9.6.4? (I have found them for 7.9.6.3 but cannot find them for .4.............if they are so similar as to have little difference then that is worth knowing as well). Thanks!

  • Exchange Files N8 with Desk Top

    Hi, seems very easy, however could not find that option at Ovi Suite to exchange files like .pdf  ; .doc  ; .xls or other that are no music, pictures, etc. Can somebody help me? Thanks Solved! Go to Solution.

  • Will iPhoto recognize duplicate image files on import?

    I was wondering if when importing image files into iPhoto 09 there are 2 files with the same name and EXIF data will iPhoto not import the dupe or at least warn that there is a file by the same name already in the catalog?