May I make a singleton pattern like this

as well know, singleton pattern in java always like the codes below:
public class ClassicSingleton {
private static ClassicSingleton instance = null;
protected ClassicSingleton() {
// Exists only to defeat instantiation.
public static ClassicSingleton getInstance() {
if(instance == null) {
instance = new ClassicSingleton();
return instance;
but, when I read the java non-static initialization block section, I had an new idea about a this pattern. how about like this:
public class ClassicSingleton {
     private static ClassicSingleton instance = null;
     protected ClassicSingleton() {
          // Exists only to defeat instantiation.
     static{
          instance = new ClassicSingleton();
     public static ClassicSingleton getInstance() {
          return instance;
or like this
public class ClassicSingleton {
     private static ClassicSingleton instance = null;
     protected ClassicSingleton() {
          // Exists only to defeat instantiation.
          instance = new ClassicSingleton();
     public static ClassicSingleton getInstance() {
          return instance;
could anybody here tell me what's the different? thanks.

I usually do something like this:
public class ClassicSingleton {
  private static ClassicSingleton instance = new ClassicSingleton();
  private ClassicSingleton() {
    try{
      /* Construction logic here. */
    }catch(Exception e){
      /* Something bad happened, decide what to do, like set a flag indicating singleton isn't valid. */
  public static ClassicSingleton getInstance() {
    return instance;
}

Similar Messages

  • How to Make a Background Texture Like This

    Can you please take a look at following image and let me know how I can create a background texture (pattern) like this in Adobe illustrator cs6?
    I already tried this using Texture -> Grain -> Artistic -> Film Grain  but the result is a little different as:
    Can you you please let me know how to do that? Thanks

    Actually you are close, it needs something like the light factory in photoshop to generate depth.
    The easiest way is to go to your local office supply store, by a sample pack of paper then scan a sheet into your computer, instant texture. You can then overlay any color you choose, depending on the original color of the paper though.

  • What do I need to do to make a forum just like this one(from apple)

    What do I need to do to make a forum just like this one(from apple)

    Wendy, as a_a has explained, when power is removed, the data is gone.
    If you want to put this problem to rest, remove either of the battery connections; this will assure the data is gone forever!
    WyreNut
    Post relates to: Centro (AT&T)
    I am a Volunteer here, not employed by HP.
    You too can become an HP Expert! Details HERE!
    If my post has helped you, click the Kudos Thumbs up!
    If it solved your issue, Click the "Accept as Solution" button so others can benefit from the question you asked!

  • Possible to make a chart look like this?

    I'd like to make a chart look like
    this.
    Is this possible and if yes with which chart type and
    settings, or if no, could someone point me to
    some tutorial or guides how to draw custom shapes and line
    with flex?
    thanks,
    Mickey

    Hi Tony,
    Fisrt it's sure to use datetime, date and time range as a dimension for
    crosstab.
    The default type of ORDERDATE is Date, so you should define a computed
    column in dataset: expression is row["ORDERDATE"] type is Date Time or
    Time. Then using them in your cube.
    If you want display like:
    Jan 1, 00:00 to 11:59 x1
    Jan 1, 12:00 to 23:59 x2
    Jan 2, 00:00 to 11:59 x3
    you should make sure that the ORDERDATE dimension is a Regular group but
    not a Date group. Because the Date group can not set the static level. Do
    you know how to set the regular dimension? In cube builder, when you drag
    ORDERDATE column into Groups, there will be a selection dialog pops up,
    you just chose the regular group is ok. Then you can define your static
    levels to display x1, x2 and x3. There is another way but now we didn't
    open this feature now, the date level will suppport user to define its
    interval(range), but the display is only the number of hour but not 11:59.
    see bug
    #189340(https://bugs.eclipse.org/bugs/show_bug.cgi?id=189340)
    Second, chart can not using the cube's dimension as an axis, chart only
    can use the dataset as its data source, please see comments #3 in
    bug#192853.
    Regards!

  • How do I create & edit a pattern like this in Illustrator?

    I want to know how to create and edit a pattern like this in Illustrator:
    And then be able to do this:
    (same pattern with blue square effect)
    Any advice would be appreciated.

    Read up on creating patterns. This one is just simple lines and very easy to do, but remember that the defining rectangle MUST be at the very back of the stack:
    Start off by making your pattern tile (top). Drag the drawing to the Swatches panel.
    Fill a rectangle with the pattern. Scale and rotate the pattern fill (see Scale and Rotate dialogues).
    Recolour the pattern using Edit > Edit Colors > Recolor Artwork

  • What app do people use to make their pictures look like this

    what app do people use to make their pictures look like this?

    Apparently redchainsaw answered back saying that wasn't it. Though looking at the pictures I see nothing odd or special about them.
    With that said however, there are many image editors in the App store, and the Instagram App does have several filters you can apply to the photos.   So its very possible that is it.

  • Do I need a Singleton pattern for this case

    Hello,
    I'm writing a game in Java and I have a very simple score manager class which just tracks the points the player so far has. I need to access this class in different pars of my app (gui, game core ...) so I created a singleton class which looks like this
    public class ScoreManager {
            private static ScoreManager instance = new ScoreManager();
            private int score = 0;
         private int highScore = 0;
         public static ScoreManager getInstance() {
              return instance;
         public int getScore() {
              return score;
         public int getHighScore() {
              return highScore;
         public void addScore(int scoreToAdd){
              score += scoreToAdd;
              if(score > highScore) {
                   highScore = score;
    }so far so good ..
    I would like to read the "highScore" from a file when the game starts and write it back when the game ends. I added those two methods:
         public void init(File highScoreFile) {
              highScore = readFromFile(highScoreFile);
                    score = 0;               
         public void dispose(File highScoreFile) {
                   writeToFile(highScoreFile);
         }So basically I call the init() method when the game stars and the dispose() when the game ends.
    It works but what I don't like is that the init() and dispose() methods are exposed and someone could call them in a wrong place.
    What would be a better way to do this ?
    Thanks for your help,
    Jesse

    safarmer wrote:
    You could keep track of the state (initialised, destroyed etc) in the manager and only perform the action if it is an expected state.
    private enum State { NOT_INITIALISED, INITIALISED, DESTROYED};
    private State currentState = State.NOT_INITIALISED;
    // i will leave the rest up to your imagination :) this looks good, thanks
    anotherAikman wrote:
    >
    It works but what I don't like is that the init() and dispose() methods are exposed and someone could call them in a wrong place. And who would that be? You´re the only one using the code, aren´t you?
    If not, you could still include in the documentation where to call those methods.
    no I'm not the only one working on this. Documentation can be useful but does not prevent calling wrong methods.
    YoungWinston wrote:
    I don't see any constructor. Usually, a singleton class should have a private one, even if it has no parameters. If you don't have any, Java will create a public no-parameter one as default.ok I forgot the private constructor.
    It works but what I don't like is that the init() and dispose() methods are exposed and someone could call them in a wrong place. Then my advice would be not to make them public. After all, your code is the only one calling these methods - yes?yes only the code of the app calls it.
    If you are convinced that your game requires one and only one score manager, then a singleton is probably the best way to go.
    I'm a little worried about the init() and dispose() methods though, because these suggest state changes, which is unusual for the singleton pattern. You may want to think about synchronizing them.
    An alternative might be to use properties to get and store your scores.ok for the synchronization. What would using the properties ? It would be just another type of storage backend and I'd still need to read/write it.
    Thanks for your help,
    J

  • How to make a fullscreen slideshow like this?

    this is an app I found that the slideshow is what I want to make,but with original slideshow I can't make it,so I really want to know the special way to do
    I am using the adobe content viewer on ipad to test my file, is it the reason? some functions are limited?
    There is a small pic, when I click it,the whole page flip, then it is a fullscreen slideshow and has some special share link

    argantara wrote:
    anyone know if i can make a text effect like in this video: http://www.youtube.com/watch?v=gRyPj...1CA12E38536E7C
    the moving one that starts in 0:23
    and also the font too. can i do it in final cut pro x? or maybe iMovie? thanks guys!
    You can use any font available on your system, so if the font is there, or can be bought or downloaded, just use it.
    As for the effect, if you mean the text flowing from right to left, you can do it in FCP X pretty easily. Either use a title meant for that sort of movement (like Alex4D Ticker+, which is a free download), or just use a static title like Basic, enter a long text and keyframe the position.
    As for the big shake, you may try the "Earthquake" effect that comes standard with FCP X.

  • How to make my website slidedown like this?

    Hello, I'm making a website. And I want to be able to make my page slide up and down like this page https://stockflare.com/landing. Can owsomeone please explain how I can do this with parallax scrolling.

    You can try this :
    http://musewidgets.com/collections/all/products/scroll-wheel-anchors
    Thanks,
    Sanjit

  • How do I make my terminal look like this?

    Hello, I'm trying to figure out how this guy made so his terminal look the way it does.
    I've searched around some sites but I can't really figure out what to look for as I don't know the name of the application or what it really is, just that it looks like that.
    http://sites.google.com/site/gotmor/dze … xmonad.png

    Rob (the dzen dev, IIRC and BTW) is probably using urxvt as a terminal. The prompt is a two-line prompt like this one, you'll need zsh for it. Also, he uses XMonad, a tiling window manager, which doesn't draw any window decorations, so there's no close/maximize/minimize buttons or title bar. Good luck getting into them all, you're in for quite a journey.

  • How do I make a text stretch like this?

    http://www.youtube.com/watch?v=YYI9tK3o2YY
    Heroes word stretches at first. How do I make that? I've glowed it like there, and blurred out like that. But I can't figure out how to strech it.
    Also, how do I create those red circles around "O" at 6th second, tutorial would be nice. I'm fairly new to this program.

    I can't see what you've posted due to network restrictions where I work, but the text stretch sounds like stuff you could accomplish by a combination of animating the scale and some of the distort effects (like Bezier Warp, Corner Pin, Mesh Distort, etc.)
    Red circles might be particles, shape layer(s), or Radio Waves depending on how it looks (again, I can't see it).
    If you're new to AE, I highly recommend you start here first: [link] Go through all of the resources that page links to. It will get you up to speed on the basics of AE which will remove a lot of the frustration a newcomer can experience.

  • How to make a photo gallery like this?

    This couple has an impressive portfolio of mtn climbing
    accomplishments that will make you want to get out of your chair:
    http://www.pfint.com/pics/peaks/RussellWhitneyMuir/RussellWhitneyMuir.htm
    I like the way the pics open in new window exactly the size
    of the picture with even black border on all sides, and close upon
    clicking. Is this an active html page or is each picture page
    created separately? (I could do that - don't want to though...)
    Would this effect be easy for a intermediate level person to
    create? Would like to find a tutorial. Or just the right
    script/code to paste in. =0)

    That was done with a Dreamweaver extension by Michael Brandt
    called
    JustSoPic window. I've used it for years. :)
    http://valleywebdesigns.com/vwd_jspw3.asp
    Nancy Gill
    Adobe Community Expert
    Author: Dreamweaver 8 e-book for the DMX Zone
    Co-Author: Dreamweaver MX: Instant Troubleshooter (August,
    2003)
    Technical Editor: Dreamweaver CS3: The Missing Manual,
    DMX 2004: The Complete Reference, DMX 2004: A Beginner's
    Guide
    Mastering Macromedia Contribute
    Technical Reviewer: Dynamic Dreamweaver MX/DMX: Advanced PHP
    Web Development
    "onefiftymph" <[email protected]> wrote in
    message
    news:gfcndi$k30$[email protected]..
    > This couple has an impressive portfolio of mtn climbing
    accomplishments
    > that
    > will make you want to get out of your chair:
    >
    http://www.pfint.com/pics/peaks/RussellWhitneyMuir/RussellWhitneyMuir.htm
    >
    > I like the way the pics open in new window exactly the
    size of the picture
    > with even black border on all sides, and close upon
    clicking. Is this an
    > active
    > html page or is each picture page created separately? (I
    could do that -
    > don't
    > want to though...) Would this effect be easy for a
    intermediate level
    > person to
    > create? Would like to find a tutorial. Or just the right
    script/code to
    > paste
    > in. =0)
    >
    >
    >
    >

  • How To Make My Photo Look Like This?

    I was really inspired by a music video on Youtube. (Ellie Goulding - Goodness Gracious - YouTube) Very nice effects and all so I tried to make one of my photo like the photos above. I tried Neon Glow Filter but it doesn't really seem like these photos above.
    How do I give my photo this kind of effect? And what to call this effect? Would you give me any advises? Thank you!

    Experiment with changing a layer's influence on your image with the "blend if" sliders in the layers blending options. (drag the sliders, alt-click to separate the sliders and make smooth transitions). the green image in your example, could be as simple as adding a plain layer with a blue-to-green gradient and changing the "blend if:grey" to only show in the darkest shadow colours of the image underneath.

  • How do I create a pattern like this in Illustrator?

    Hello,
    I know how to create a dotted pattern using swatches or brushes but this pattern is benden afterwards. I really need to have the same bended effect.
    In the middel the dots are aligned perfectly vertically next to one another, at the bottom not anymore...

    Make scatter brush out of a row of circles
    Apply to a curved path
    expand appearance
    apply color

  • How do I make a loading screen like this one?

    Okay, so for my loading screen, I want a block to appear for every 10% loaded (so they'red be 10 blocks at the end).  I know how to make a loading bar, but I'm having trouble making this one.  Any help? Thanks.

    There are probably a number of ways to approach it.  One would be to have a movieclip with 10 frames where a new box is manually added in each frame.  You use the percent loaded information to tell that movieclip which frame to go to.

Maybe you are looking for

  • Report 6i rdf's and XML Publisher

    I'm trying to decide whether to implement Reports Developer 10g or XML Publishing as our reporting tool. Can I get some feedback from XML Publisher users who have also worked with the Oracle reporting tool Reports 6i? (I'm currently working with 6i)

  • Video synced but no audio

    I am using the Nokia C2-03 phone, and I've got recorded videos which I've synced onto the Nokia Suite (vers 3.8.30). They play fine but there is no audio. The audio plays fine on the phone, but has not synced with the video onto the suite. I've looke

  • How to create a database link ?

    i want to create a database link.please give mesteps

  • ACTION_UPDATE of tables with 32 columns

    Is anyone else having this problem: SQLEXCEPTION SQL command not ended properly. I have a model of a single table with more than 32 columns. I get this error whenever I use the WebActionCommand ACTION_UPDATE. But only on this table.

  • Custom Update of the Logistics Execution status on the FO header

    Hi, in our project, we are using an app to update the statuses of the Freight Units. On the Fo, we are updating departure, arrival, load and unload. In standard, the logistical execution status has the last event on the header. Thats useful when you