Nando,

That doesn't quite work, because when you call onApplicationStart, you
need to single thread ALL access to the application, which is very
difficult to do manually.  More specifically, you must ensure that no
more than one request executes the initialization code, and that from
the time the initialization starts to the time it ends, no other
requests execute in the application.  What you proposed won't do it. 
That's part of the wonderfulness of the new event.

What you need is something like this protecting your initialization:

<cfif structKeyExists(application, "initialized")>
<cflock scope="application" type="exclusive" timeout="1">
<cfif structKeyExists(application, "initialized")>
  <!--- all app initialization --->
  <cfset application.initialized = true />
</cfif>
</cflock>
</cfif>

AND you also need some way of letting currently running requests
finish without letting any new requests start, so you can get to a
point where there are no requests currently running.  Then you delete
application.initialized, and then you can let requests start running
again.  It's a VERY messy process.

Really, the bottom line is that under load, you have to either change
the application name or restart CF to properly reinitialize the
application, whether you're using a home-grown system or
onApplicationStart.  Really no way around it.  I usually opt for the
renaming the application, using a incrementing counter at the end, so
my application name might be "myApp1", and when I need to
reinitialize, I change it to "myApp2".  The reason this works is
because any requests that are currently executing remain on myApp1
while myApp2 (a completely separate application) starts up.  The
downside is that if you have a lot of application variables, the
variables from myApp1 linger on the server, totally unused until the
configured application timeout.

cheers,
barneyb

On Sat, 12 Mar 2005 14:38:00 +0100, Nando <[EMAIL PROTECTED]> wrote:
> Barney,
> 
> The docs state that you can call the onStartApplication event,
> 
> "If you call this method explicitly, ColdFusion does not start the
> application; it does execute the method code, but does not lock the
> Application scope while the method executes."
> 
> What does that leave us with as a "best practice" for reinitalizing
> application scoped cfc's during development. I'm wondering about
> adding a method to application.cfc immediately under
> onApplicationStart, say restartApp, include the same createObject
> calls, but lock them. I'm hoping i can add something like
> 
> if (StructKeyDefined(url, "restart")) {
>   restartApp();
> }
> 
> in onRequestStart - not 100% sure if url scoped variables are
> available to onRequestStart tho'. Have to give that a try.


-- 
Barney Boisvert
[EMAIL PROTECTED]
360.319.6145
http://www.barneyb.com/

Got Gmail? I have 50 invites.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Discover CFTicket - The leading ColdFusion Help Desk and Trouble 
Ticket application

http://www.houseoffusion.com/banners/view.cfm?bannerid=48

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:198570
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to