File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Static vs Single Pattern Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic
Author

Static vs Single Pattern

salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 917



My Website: [Salvin.in] Cool your mind:[Salvin.in/painting] My Sally:[Salvin.in/sally]
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Janeice wrote: 2: What, if any, are the problems with the Singleton pattern, exclusive of the issue of threadsafety (which is supposedly fixed by the "volatile" labeling)
All the other issues in the blog posts I already provided twice, and summarized above.

Regarding the double-locking/threading issue which appears to be a major focus for you:

If you'd read the IBM post you provided, you would have read this:
Editor's note: This article refers to the Java Memory Model before it was revised for Java 5.0; statements about memory ordering may no longer be correct. However, the double-checked locking idiom is still broken under the new memory model. For more information on the memory model in Java 5.0, see "Java theory and practice: Fixing the Java Memory Model" Part 1 and Part 2.
Part 1 of the reference includes the following:
It is worth noting that broken techniques like double-checked locking are still broken under the new memory model, and that "fixing" double-checked locking was not one of the goals of the new memory model effort. (However, the new semantics of volatile allow one of the commonly proposed alternatives to double-checked locking to work correctly, although the technique is still discouraged.)
Part 2 of the reference includes the following: http://www.ibm.com/developerworks/library/j-jtp03304/#3.2

I really, really hope this stops further discussion about the double-locking thing.
Ulrika Tingle
Ranch Hand

Joined: Nov 24, 2009
Posts: 92
Janeice DelVecchio wrote:I never said singletons were good or bad. I just don't know. Actually, my very first post said I made no assertions whether or not they should be used or not. I said I understood the basic concept of why someone would use it over a static variable. Rather, I think I just compared the two, not even made an assertion of why it should be used over a static variable.

What I said was that no one could tell me (on a foundational level) what the heck is wrong with using them. Everyone here has said "they're bad," "don't use them," et cetera.

I got links to blog posts from several years ago. Are these people respected in the field? I have no idea. No one said, "please see Joe Shmoe's blog, he's a such and such person in the blah blah industry for x years. He did studies for blah company."

When I questioned the sources, on an academic level, no one could defend the fact that the sources were blogs. No one could find a reputable source (or at least define what makes the blogs reputable).

If someone could tell me, in normal person language:
1: Why doesn't the JDK5 "volatile label fix" work to fix the singleton problem?
2: What, if any, are the problems with the Singleton pattern, exclusive of the issue of threadsafety (which is supposedly fixed by the "volatile" labeling)

I am really through with feeling like I have to defend myself. Just because I ask questions doesn't mean I'm questioning anyone's judgement, it just means I'm not going to take advice on face value no matter how long you've been following it.


Well, to cut all the crap why don't you just ask people to come up with a better solution to my postoffice Singleton?

What I'm using here is a variation of the Occam's razor, or the simplest solution is the correct one. Show a simpler solution to the postoffice Singleton and Singleton itself is in question. But until then, Singleton rules.
Ulrika Tingle
Ranch Hand

Joined: Nov 24, 2009
Posts: 92
To my previous post.

You can find anything on the internet, including that OO sucks. The fact that some people on the internet think that Singleton sucks is in itself not a proof that Singleton is bad.

The fact that it's hard to perfectly implement a Singelton is in itself not a proof that Singleton sucks. Lots of very useful things are hard to implement, many of them even harder than a Singelton.

The fact that people misuses Singelton is not a proof that Singelton sucks. People misuses all sorts of language elements in every programming paradigm all the time.

So the only real test of the usefulness of Singleton is to apply Occam's razor as I explained in my previous reply.
salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 917

Ulrika Tingle wrote:To my previous post.

You can find anything on the internet, including that OO sucks. The fact that some people on the internet think that Singleton sucks is in itself not a proof that Singleton is bad.

The fact that it's hard to perfectly implement a Singelton is in itself not a proof that Singleton sucks. Lots of very useful things are hard to implement, many of them even harder than a Singelton.

The fact that people misuses Singelton is not a proof that Singelton sucks. People misuses all sorts of language elements in every programming paradigm all the time.

So the only real test of the usefulness of Singleton is to apply Occam's razor as I explained in my previous reply.


I agree with the given post and in a kinder way:
yes, there are people who hate things, but its never justified that all should hate them because you hate them....
salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 917

Quite honestly I find this post to contain a variety of arguements,
but no one here has shaken up my beliefs in singletons,
not only that, no one has an alternative soln for the post office example...

and yes, many of the blogs are more opinions than facts as suggested by Janeice DelVecchio
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Then define a "fact". I don't see how anybody could argue in any reasonable way against what the blog posts say.

If you decide to try, please start a new thread in an appropriate forum; I'm locking this one.
 
Consider Paul's rocket mass heater.
 
subject: Static vs Single Pattern
 
Similar Threads
Static methods
Using characters like quote, ampersand in xml
can a class be static?
Override JComboBox toString() behavior?
Restricting the number of objects