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.
ColdFusion Adobe Community Professional
Hello Daniel, here's the code...I changed some variable names, do not wonder...
<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() />
At the moment of object creation, the application scope is already filled with some data which is defined above.
Now the method object.initAll():
<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) />
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.
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.
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?
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?