Avoid Zero (or super short) Application Timeouts

This post is more than 2 years old.

So here's a doozy for you. Over the past week or so I exchanged emails with a reader who was having an odd issue with ColdFusion mappings. Specifically the code he wrote to actually use the mappings would fail to work if he used application specific mappings. Switching to mappings defined on the server fixed it.

After I failed to notice it (and you can guess what's coming up based on the title of the entry), user BKBK on the Adobe forums pointed out that he had a 0-length application timeout: this.applicationTimeout = createTimeSpan(0,0,0,0);. Basically the application, and its settings, including the application mappings, timed out before his code could use it.

Why did he have it in the first place? He wanted a simple way to reload the Application on every request. For that I'd simply use a hook in your onRequestStart to run onApplicationStart():

function onRequestStart(string req) {

To be clear, this is not really reloading the application. It is just manually running your onApplicationStart method which is - 99% of the time - probably want you want. (During testing anyway, not in production.) You can also wrap that with a simple if(structKeyExists(url, "init")) block as well.

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Archived Comments

Comment 1 by Phillip Senn posted on 8/9/2014 at 12:33 AM

A lot of hay has been made with instantiating components in the application scope.

This meant that you'd have to reload the application every time you made a change to a component.

But ColdFusion and Railo have made tremendous speed gains in terms of components being instantiated.

I no longer use the Application scope to store my components. I simply instantiate them when I need them.

The only time I forsee putting a component in memory is if I'm calling it inside a loop.
And with all the different layers of caching, it's probably in memory anyway.

Comment 2 by Adam Cameron posted on 8/9/2014 at 10:25 AM

So does this mean that settings a request acquires from the application, like mappings, ORM settings, what-have-you are removed - mid request - if the application times-out?

And application idle time is based on when the most recent request STARTS, not when it ENDED?

Both sound like our design to me..?


Comment 3 by Adam Cameron posted on 8/9/2014 at 10:26 AM

Oops! "poor design" not "our design".

Comment 4 by Raymond Camden posted on 8/9/2014 at 4:50 PM

Well, I tried to build a small test to demonstrate this. I used the cfapplication tag in a non-Application.cfm file, which you are allowed to do of course, and used sleep(). I wasn't able to replicate it there. But I still think it might be the *start* of a request as you say.

I could see the reasoning behind that being that if you wait till the end, your app, or session, may time out at a value *longer* than you defined because the request took look.

Not saying that's why, just that it may be a reason.