DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Roy Lachapelle Guest

    Track Performance of Distributed Systems


    In the Downloadable examples, Masocode.zip, the java code for Syslog.java
    has a method:

    public static synchronized Syslog instance() {
    if (instance != null)
    instance = new Syslog();
    return instance;
    }

    Shouldn't that be ' if (instance == null) ' to perform as a 'hybrid' singleton
    ?
    (I say 'hybrid' because the constructor is not private...)

    And even if a new instance was desired each time, then the instance needs
    to be
    initialized somewhere, possibly in the constructor.

    -Roy

  2. #2
    Chris P. Guest

    Re: Track Performance of Distributed Systems


    "Roy Lachapelle" <Roy.Lachapelle@Travelersla.com> wrote:
    >
    >In the Downloadable examples, Masocode.zip, the java code for Syslog.java
    >has a method:
    >
    >public static synchronized Syslog instance() {
    > if (instance != null)
    > instance = new Syslog();
    > return instance;
    > }
    >
    >Shouldn't that be ' if (instance == null) ' to perform as a 'hybrid'

    singleton
    >?
    >(I say 'hybrid' because the constructor is not private...)
    >
    >And even if a new instance was desired each time, then the instance needs
    >to be
    >initialized somewhere, possibly in the constructor.
    >
    >-Roy


    thanks for your question. I've alerted Brian to this, and he should be posting
    an answer shortly.

    /cp
    devX.com




  3. #3
    Brian Maso Guest

    Re: Track Performance of Distributed Systems


    [From the author, Brian Maso]

    Yes, Roy is exactly correct. I should have checked this part of the code,
    which was not exercised in the sample program.

    The idea of the single instance would be for an application that has maby
    different components sending syslog messages off. Rather than have each one
    create an independent Syslog instance (with all the resource expence associated),
    they can all just share a single stateless Syslog instance available through
    the static method.

    Of course the static method would have to be written correctly...

    Thanks for finding that, Roy. A corrected version of the zip file with be
    available soon.

    Brian Maso

    "Roy Lachapelle" <Roy.Lachapelle@Travelersla.com> wrote:
    >
    >In the Downloadable examples, Masocode.zip, the java code for Syslog.java
    >has a method:
    >
    >public static synchronized Syslog instance() {
    > if (instance != null)
    > instance = new Syslog();
    > return instance;
    > }
    >
    >Shouldn't that be ' if (instance == null) ' to perform as a 'hybrid'

    singleton
    >?
    >(I say 'hybrid' because the constructor is not private...)
    >
    >And even if a new instance was desired each time, then the instance needs
    >to be
    >initialized somewhere, possibly in the constructor.
    >
    >-Roy



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links