Nov 22nd, 2010, 08:14 AM
WebFlow, Timers, and FlowScope
This is an issue I encountered that I struggled to find a solution to. Just wanted to post this topic so that the next poor person who encounters the same problem can find the solution here.
So, in an action state, I was creating a four minute timer. That timer would access flow-scope and modify one of the values stored in it. Later (in a separate action state), I would access flow-scope to check to see if that value was set. The dilemma was that the value was NEVER set, even if the timer-task executed after timer expiry. In debugging, I noticed that if my timer expired BEFORE the return statement for the action, then flow-scope would contain the correct value. But, if my timer expired AFTER the action state function had returned, the value was lost.
The solution was actually to use conversation-scope instead of flow-scope. I believe (and please correct me if I am wrong) that flow-scope gets serialized between states, and that conversation-scope does not. Because I was changing the value after the action state function had completed, the flow scope attribute map had already been serialized, and my values were lost. Apparently, conversation-scope does not serialize, so this problem does not occur.
Feel free to correct me or post a comment. I'm relatively new to web-flow, so it would not surprise me if I said something incorrectly.
Nov 22nd, 2010, 12:47 PM
Yep, absolutely correct.
I feel that the documentation for SWF doesn't adequately cover the snapshot and serialization process, and the implications for multithreaded code. A guide to USING SWF is fine...but users shouldn't need to stumble into this to discover the limitations or characteristics of the system.
Tags for this Thread