Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
ColdFusion Design Patterns site - Singleton
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  20 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Sean Corfield  
View profile  
 More options Dec 11 2009, 1:13 am
From: Sean Corfield <seancorfi...@gmail.com>
Date: Thu, 10 Dec 2009 22:13:55 -0800
Local: Fri, Dec 11 2009 1:13 am
Subject: ColdFusion Design Patterns site - Singleton
The Singleton Provider code is not thread safe (since it does not lock
modifications of variables scope which is essentially application
scope). This is why literal implementations of the Singleton pattern
is so hard in C++ / Java etc - synchronization, threading (and
preventing multiple instance creation).

The Singleton Provider doesn't prevent multiple instances because you
can simply create multiple provider objects. It really provides no
value and simply adds complexity. IMO.

Folks either need to go with something battle-tested like ColdSpring
to manage singletons or stick with the simple onApplicationStart()
approach.
--
Sean A Corfield -- (904) 302-SEAN
Railo Technologies US -- http://getrailo.com/
An Architect's View -- http://corfield.org/

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kevan Stannard  
View profile  
 More options Dec 11 2009, 3:41 am
From: Kevan Stannard <kevanstann...@gmail.com>
Date: Fri, 11 Dec 2009 19:41:15 +1100
Local: Fri, Dec 11 2009 3:41 am
Subject: Re: [coldfusionoo] ColdFusion Design Patterns site - Singleton

I'll fix that thread safe issue, thanks.

I'm taking the approach that we can't enforce singletons in CFML in any
reasonable way, so it is more by convention that a provider should be
created once on application startup.

I proabably didn't get the idea across too well, but the Singleton Provider
is a intended to be a pattern that represents an object factory for
singletons. I think there is value to include it because of the common usage
of factories to manage singletons. Perhaps the pattern itself should be
called Singleton Factory?

Considering what you've mentioned I may include a section that refers to
ColdSpring and perhaps Lightwire.

Thanks

2009/12/11 Sean Corfield <seancorfi...@gmail.com>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Sean Corfield  
View profile  
 More options Dec 11 2009, 3:45 am
From: Sean Corfield <seancorfi...@gmail.com>
Date: Fri, 11 Dec 2009 00:45:50 -0800
Local: Fri, Dec 11 2009 3:45 am
Subject: Re: [coldfusionoo] ColdFusion Design Patterns site - Singleton
On Fri, Dec 11, 2009 at 12:41 AM, Kevan Stannard

<kevanstann...@gmail.com> wrote:
> I proabably didn't get the idea across too well, but the Singleton Provider
> is a intended to be a pattern that represents an object factory for
> singletons. I think there is value to include it because of the common usage
> of factories to manage singletons. Perhaps the pattern itself should be
> called Singleton Factory?

I think the problem with what's there right now is people will see the
simple singleton wrapper and mindlessly follow it with understanding
you mean a factory (that can create a number of different singletons).
--
Sean A Corfield -- (904) 302-SEAN
Railo Technologies US -- http://getrailo.com/
An Architect's View -- http://corfield.org/

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kevan Stannard  
View profile  
 More options Dec 11 2009, 3:50 am
From: Kevan Stannard <kevanstann...@gmail.com>
Date: Fri, 11 Dec 2009 19:50:13 +1100
Local: Fri, Dec 11 2009 3:50 am
Subject: Re: [coldfusionoo] ColdFusion Design Patterns site - Singleton

Yep, I see what you mean. I'll rework it a bit, thanks.

2009/12/11 Sean Corfield <seancorfi...@gmail.com>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Patrick Santora  
View profile  
 More options Dec 11 2009, 10:47 am
From: Patrick Santora <patwe...@gmail.com>
Date: Fri, 11 Dec 2009 07:47:57 -0800
Local: Fri, Dec 11 2009 10:47 am
Subject: Re: [coldfusionoo] ColdFusion Design Patterns site - Singleton

Understandably Coldspring would be ideal way to create "complex" singletons,
but out of curiosity if a CF developer ever decided to build a singleton
provider class on their own I would think something like the below would
suffice. It's a quick example, but I figure that the application scope would
be encapsulated within the component to help ensure that there is only one
instance of the object application wide. I am curious on everyone's thoughts
on this outside of using Coldspring.

*<cfcomponent name="singletonAProvider">

<cffunction* name="getInstance" output="false">

    *<cfif* not structKeyExists(application,"singletonA")>

        *<cfset* application.singleton =
createObject("component","SingletonA").init()>

    *</cfif>*
    *<cfreturn* application.singleton>

*</cffunction>

</cfcomponent>
*

-Pat

On Fri, Dec 11, 2009 at 12:50 AM, Kevan Stannard <kevanstann...@gmail.com>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Patrick Santora  
View profile  
 More options Dec 11 2009, 11:03 am
From: Patrick Santora <patwe...@gmail.com>
Date: Fri, 11 Dec 2009 08:03:21 -0800
Local: Fri, Dec 11 2009 11:03 am
Subject: Re: [coldfusionoo] ColdFusion Design Patterns site - Singleton

I forgot to mention. I thought of the application scope because it's the
closest thing to the global scope in java even though it can't be fully
protected.

-Pat


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Sean Corfield  
View profile  
 More options Dec 11 2009, 12:00 pm
From: Sean Corfield <seancorfi...@gmail.com>
Date: Fri, 11 Dec 2009 09:00:16 -0800
Local: Fri, Dec 11 2009 12:00 pm
Subject: Re: [coldfusionoo] ColdFusion Design Patterns site - Singleton

On Fri, Dec 11, 2009 at 7:47 AM, Patrick Santora <patwe...@gmail.com> wrote:
>     <cfif not structKeyExists(application,"singletonA")>
>         <cfset application.singleton =
> createObject("component","SingletonA").init()>
>     </cfif>

You still want if / lock / if here to avoid a race condition that can
construct SingletonA twice!
--
Sean A Corfield -- (904) 302-SEAN
Railo Technologies US -- http://getrailo.com/
An Architect's View -- http://corfield.org/

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Patrick Santora  
View profile  
 More options Dec 11 2009, 6:26 pm
From: Patrick Santora <patwe...@gmail.com>
Date: Fri, 11 Dec 2009 15:26:06 -0800
Local: Fri, Dec 11 2009 6:26 pm
Subject: Re: [coldfusionoo] ColdFusion Design Patterns site - Singleton

Ah of course. Sounds like a yes as long as the lock is in place.

On Fri, Dec 11, 2009 at 9:00 AM, Sean Corfield <seancorfi...@gmail.com>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kevan Stannard  
View profile  
 More options Dec 11 2009, 9:18 pm
From: Kevan Stannard <kevanstann...@gmail.com>
Date: Sat, 12 Dec 2009 13:18:14 +1100
Local: Fri, Dec 11 2009 9:18 pm
Subject: Re: [coldfusionoo] ColdFusion Design Patterns site - Singleton

I've updated the Singleton page

http://www.coldfusiondesignpatterns.org/wiki/Singleton

Couple of changes

* Renamed Singleton Provider to Singleton Factory
* The example creates the singletons when the factory is created - no lazy
instantiation, and the example shows the factory being created in
onApplicationStart() so I have not included locking.
* I have included an additional example of singleton management using
ColdSpring. Considering that was the intent of the original "singleton
provider" this hopefully introduces a real world example of more advanced
singleton management.

What does everyone think? Is this representative of how singletons should be
managed in CFML?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kevan Stannard  
View profile  
 More options Dec 11 2009, 9:26 pm
From: Kevan Stannard <kevanstann...@gmail.com>
Date: Sat, 12 Dec 2009 13:26:28 +1100
Local: Fri, Dec 11 2009 9:26 pm
Subject: Re: [coldfusionoo] ColdFusion Design Patterns site - Singleton

Pat and I have discussed this approach and I can see that there is a place
for code that encapsulates access to the application scope, but I am not
convinced it should be promoted as a technique for managing singletons.

2009/12/12 Patrick Santora <patwe...@gmail.com>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pat Santora  
View profile  
 More options Dec 11 2009, 10:50 pm
From: Pat Santora <patwe...@gmail.com>
Date: Fri, 11 Dec 2009 19:50:53 -0800
Local: Fri, Dec 11 2009 10:50 pm
Subject: Re: [coldfusionoo] ColdFusion Design Patterns site - Singleton

Understandable but a viable approach to the pattern nevertheless.

I an curious what other people think as this example (unless wrong) is  
a GoF expressed example and an understandably good one when working  
outside of the onapplicationstart method approach.

Just another duck on the table :)

Sent from my iPhone

On Dec 11, 2009, at 6:26 PM, Kevan Stannard <kevanstann...@gmail.com>  
wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pat Santora  
View profile  
 More options Dec 11 2009, 11:06 pm
From: Pat Santora <patwe...@gmail.com>
Date: Fri, 11 Dec 2009 20:06:49 -0800
Local: Fri, Dec 11 2009 11:06 pm
Subject: Re: [coldfusionoo] ColdFusion Design Patterns site - Singleton

Amended to the email I just sent...

Of course the GoF approach has nothing about onapplicationstart in it  
for obvious reasons. It just seems like a good approach to manage  
singleton creation outside of the onapplicationstart method when not  
having something like coldspring available.

Btw this is not meant to shove its way into the existing  
documentation. Curiosity just has my fingers talking. :)

I'm quite excited about the website Kevan!!!

-Pat

Sent from my iPhone

On Dec 11, 2009, at 6:26 PM, Kevan Stannard <kevanstann...@gmail.com>  
wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Sean Corfield  
View profile  
 More options Dec 12 2009, 2:08 am
From: Sean Corfield <seancorfi...@gmail.com>
Date: Fri, 11 Dec 2009 23:08:39 -0800
Local: Sat, Dec 12 2009 2:08 am
Subject: Re: [coldfusionoo] ColdFusion Design Patterns site - Singleton

That works for me.

In my Design Patterns preso (originally written for the MAX "Inspire" track
a few years ago) I lampooned how complex all the Java Singleton
implementations are because Java doesn't have:
a) a global scope like application
b) an application start point like onApplicationStart() (the main() method
doesn't count - any class can have that so there's no *single* application
entry point)
c) any easy way to manage when or where a Singleton is actually created

Singleton implementation in ColdFusion is trivial by design.

The whole thing about "preventing more than one instance" is really only
applicable to language implementations where this is likely due to the
points above...

Sean

On Fri, Dec 11, 2009 at 6:18 PM, Kevan Stannard <kevanstann...@gmail.com>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Phillip Senn  
View profile  
 More options Dec 12 2009, 10:33 am
From: Phillip Senn <phillips...@gmail.com>
Date: Sat, 12 Dec 2009 10:33:14 -0500
Local: Sat, Dec 12 2009 10:33 am
Subject: Re: [coldfusionoo] ColdFusion Design Patterns site - Singleton

Do you need to lock the application scope, or is that implied in
onApplicationStart?

On Fri, Dec 11, 2009 at 9:18 PM, Kevan Stannard <kevanstann...@gmail.com>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Sean Corfield  
View profile  
 More options Dec 12 2009, 6:55 pm
From: Sean Corfield <seancorfi...@gmail.com>
Date: Sat, 12 Dec 2009 15:55:19 -0800
Local: Sat, Dec 12 2009 6:55 pm
Subject: Re: [coldfusionoo] ColdFusion Design Patterns site - Singleton

On Sat, Dec 12, 2009 at 7:33 AM, Phillip Senn <phillips...@gmail.com> wrote:
> Do you need to lock the application scope, or is that implied in
> onApplicationStart?

onApplicationStart() (and onSessionStart()) are automatically
single-threaded by the CFML engine (so, no, you don't need to lock).
--
Sean A Corfield -- (904) 302-SEAN
Railo Technologies US -- http://getrailo.com/
An Architect's View -- http://corfield.org/

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Raymond Camden  
View profile  
 More options Dec 12 2009, 9:25 pm
From: Raymond Camden <rcam...@gmail.com>
Date: Sat, 12 Dec 2009 20:25:31 -0600
Local: Sat, Dec 12 2009 9:25 pm
Subject: Re: [coldfusionoo] ColdFusion Design Patterns site - Singleton
You don't need to lock if you let them run "normally." If you run the
methods manually (many people will add a call to onApplicationStart
inside their onRequestStart if a URL param exist) then you may need a
lock. Of course, you only need a lock if you actually care about a
race condition. 99% of the code I see in application startup just
initializes a set of variables.

On Sat, Dec 12, 2009 at 5:55 PM, Sean Corfield <seancorfi...@gmail.com> wrote:
> On Sat, Dec 12, 2009 at 7:33 AM, Phillip Senn <phillips...@gmail.com> wrote:

>> Do you need to lock the application scope, or is that implied in
>> onApplicationStart?

> onApplicationStart() (and onSessionStart()) are automatically
> single-threaded by the CFML engine (so, no, you don't need to lock).
> --
> Sean A Corfield -- (904) 302-SEAN
> Railo Technologies US -- http://getrailo.com/
> An Architect's View -- http://corfield.org/

> "If you're not annoying somebody, you're not really alive."
> -- Margaret Atwood

--
===========================================================================
Raymond Camden, ColdFusion Jedi Master

Email    : r...@camdenfamily.com
Blog      : www.coldfusionjedi.com
AOL IM : cfjedimaster

Keep up to date with the community: http://www.coldfusionbloggers.org


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dennis Clark  
View profile  
 More options Dec 13 2009, 3:03 pm
From: Dennis Clark <boomf...@gmail.com>
Date: Sun, 13 Dec 2009 15:03:12 -0500
Local: Sun, Dec 13 2009 3:03 pm
Subject: Re: [coldfusionoo] ColdFusion Design Patterns site - Singleton

Race conditions caused by directly invoking application or session
initialization code often require more thought than simply throwing a cflock
around the call. I decided to write a blog entry to explain:

Boomerang Fish: ColdFusion shared scopes and race
conditions<http://blog.bullamakanka.net/2009/12/coldfusion-shared-scopes-and-rac...>

-- Dennis


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Sean Corfield  
View profile  
 More options Dec 13 2009, 5:32 pm
From: Sean Corfield <seancorfi...@gmail.com>
Date: Sun, 13 Dec 2009 14:32:32 -0800
Local: Sun, Dec 13 2009 5:32 pm
Subject: Re: [coldfusionoo] ColdFusion Design Patterns site - Singleton

Brilliant post! Should be required reading for every CFer!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Patrick Santora  
View profile  
 More options Dec 13 2009, 7:20 pm
From: Patrick Santora <patwe...@gmail.com>
Date: Sun, 13 Dec 2009 16:20:08 -0800
Local: Sun, Dec 13 2009 7:20 pm
Subject: Re: [coldfusionoo] ColdFusion Design Patterns site - Singleton

Great post. I love how stories can help get a point across!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Phillip Senn  
View profile  
 More options Dec 14 2009, 8:56 am
From: Phillip Senn <phillips...@gmail.com>
Date: Mon, 14 Dec 2009 05:56:22 -0800 (PST)
Local: Mon, Dec 14 2009 8:56 am
Subject: Re: ColdFusion Design Patterns site - Singleton
Oh, so the problem is not in the code that you're looking at
(onApplicationStart), but the fact that you are reinitializing a
shared scope while someone else is using it another part of the
system.

I got it.

On Dec 13, 3:03 pm, Dennis Clark <boomf...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »