Reputation: 10043
I am working on a CF9 application, and we have a process that is sometimes required that calls applicationStop()
My understanding of this function is that it shuts down the app, and the app is restarted on next request.
I am using this to reload some application scoped variables and third party stuff, however, it appears as though the onApplicationStart()
function is being called before the onApplicationEnd()
function has finished processing.
Can anyone confirm if this is intended functionality of the applicationStop()
function? The problem it is causing me is that in onApplicationEnd()
I am reseting some application scoped stuff which i want to be re-initialised in onApplicationStart()
, but if it does not wait until onApplicationEnd()
finishes then I get into an inconsistent state.
EDIT The question was originally really more about whether or not it was expected behaviour that onApplicationStart() was being called whilst onApplicationEnd() was still executing, and I was going to fix my problem with using a lock in onApplicationEnd() to make sure it finished its reloading.
However, I have added a lock:
lock scope="application" type="exlusive" timeout="5" {
And it just seems to ignore the whole block - none of the code (logging including) is executed, and no exceptions are thrown (exceptions are thrown if a lock timesout before executing right?). I assume this is related to the fact that we don't really have the complete application scope in the onApplicationEnd()?
Upvotes: 1
Views: 649
Reputation: 29870
I didn't know the answer for this, so I researched it moderately thoroughly and published my findings.
The bottom line is you should expect it because it does happen. I don't think this is a bug because the onApplicationStart()
/ onApplicationEnd()
methods are event handlers, and not the events themselves, so that one takes a while to run and the other might also be called in the interim is completely legit.
However I think in reality they should be synchronised, as it's not going to be desirable for the code from each to be running concurrently.
I didn't check the locking thing, but might have a look after that coffee I mentioned in my blog article.
Upvotes: 3