Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
I think you're okay with the lock, especially if you're going to be calling this from other locations. Are you certain that you don't have any other actions happening against the Application scope when that code runs?
Dan
Copy link to clipboard
Copied
Hello Daniel,
I assume that nothing else is running.
I restart my server, then open my browser and load the page.
Then I also assume that the way is:
onApplicationStart -> onSessionStart -> onRequestStart -> onRequest
I create the Object in onApplicationStart and set it to the application scope. Then I access this object and execute the method "initAll". The first thing in this method is to lock the application scope.
I don't know what code else could be access the application scope at this time...
Maybe the lock self is the problem, because onApplicationStart is single threaded and no lock is needed?
Is there a possibility to ask the adobe cf dev team directly?