1

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()?

15
  • Have you looked at Ben Nadel's article about it at bennadel.com/blog/…
    – Lance
    Apr 8, 2013 at 15:56
  • Yes, that seems to talk more about sessions and doesn't really touch on the onApplicationStop() function
    – rhinds
    Apr 8, 2013 at 16:01
  • You could try exclusively locking the Application Scope using a CFLOCK with the code contained in onApplicationEnd(). I thought that onApplicationEnd was single threaded so this was not necessary.
    – BKK
    Apr 8, 2013 at 16:15
  • 3
    why not just call onApplicationStart() to re-up the application?
    – genericHCU
    Apr 8, 2013 at 16:20
  • Yeah, I have added the lock to the onApplicationEnd(), I just wanted to understand whether this was the expected/known behaviour.
    – rhinds
    Apr 8, 2013 at 16:23

1 Answer 1

3

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.

3
  • Great thanks, good to know it is expected behaviour. Will accept this answer but would still like to hear any thoughts you have on how to synchronize the onApplicationEnd function
    – rhinds
    Apr 9, 2013 at 7:34
  • Yup, will do. Will feed back tomorrow (need to get work done @ the moment) Apr 9, 2013 at 8:37
  • @rhinds: I've solved that locking issue for you mate: adamcameroncoldfusion.blogspot.co.uk/2013/04/… Apr 9, 2013 at 23:30

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.