Skip to main content
Participant
November 23, 2010
Question

error cflock application in cfc after coldfusion server restart

  • November 23, 2010
  • 1 reply
  • 922 views

Hello,

I have a cfc which will be created in the "onRequestStart" method of application.cfc.

In this loaded cfc I will lock the application scope.

Everything is fine, but on the first run after I restart my coldfusion server I get a timeout error message.

The only thing I do in this cfc is to delete some keys from application scope.

Can someone help?

Do I need to clean application scope on first start?

On the first start the application scope is always empty, isn't it?

greets,

sven

This topic has been closed for replies.

1 reply

November 23, 2010

HI Sven,

You're correct, that when the application first starts, the Application scope is empty. However, by the time you get to the onRequestStart method, the applications cope has been initialized.

Can you post the contents of your onApplicationStart and onRequestStart methods, so we can see how you're locking the scopes? It might also be helpful to see the code that's running in your CFC. Otherwise we'll all be taking guesses on this one.

Daniel Short

ColdFusion Adobe Community Professional

Participant
November 23, 2010

Hello Daniel, here's the code...I changed some variable names, do not wonder...

Application.cfc

<cffunction name="onApplicationStart" access="public" output="false" returntype="boolean">

....

<!--- set some keys in application scope here, like Application.CFC_Path --->

<cfset Obj = createObject("component","#Application.CFC_Path#.Object") />
<cfset Application.object= Obj />
<cfset Application.object.initAll() />

...

</cffunction>


At the moment of object creation, the application scope is already filled with some data which is defined above.

Now the method object.initAll():

object.cfc

<cffunction name="initAll" access="public" output="no">

<cfset var appKeyList = structKeyList(Application) />

        <cflock scope="Application" timeout="2" type="exclusive">
            <cfloop list="#appKeyList#" index="clearKey">
                <cfif clearKey CONTAINS "sometext">
                    <cfset structDelete(Application,clearKey) />
                </cfif>
            </cfloop>
        </cflock>

</cffunction>

At the moment my solution is to increase the value of the timeout. But I think, when starting this method, there is no access on application scope, so why the timeout exceeds after 2 seconds? Multithreading?

Theres only one instance of my browser which access the page.

An other solution could be to do not try to delete the keys in application scope, because they do not exist at first start.

But how I can determine if the application was started the first time? This method ("initAll") will also be called outside the onApplicationStart from a "admin" cfm script.

greets,

Sven

ilssac
Inspiring
November 23, 2010

I would like to point out that your locking may be unnecessary.  The OnApplicationStart() function automatically is single threaded so locking code inside it should be unnecessary.

Now since you are calling another function, that may make a difference.  But you may want to investigate how this might impact your code.