Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Workflow Object State Not Updating Inside of Thread

Avatar

Level 1

Hello all!

 

I have a service set up that runs sub-workflows in batches based on a set size (currently 15 but configurable to other values). It is multi-threaded (I have tested the concurrency and it appears to follow an appropriate ordering 100% of the time). The goal is to have a parent thread call workflowSession.startWorkflow(...), wait until the workflow completes, then release its thread back to the pool (I'm actually using a semaphore and an ExecutorService which might not both be necessary but shouldn't affect how anything works). The way I am accomplishing waiting until a workflow is completed is waiting the thread on a monitor stored in a map with the key being the workflow id. An EventHandler listens for workflow complete events and calls notify on that map at the workflow id (these are currently lining up properly).

 

The issue that I am having is that I have a while guard (surrounding the wait call) that loops while the workflow.isActive(). The local workflow object appears to always be in a RUNNING and isActive = true state (I have checked that the event timing isn't the issue by allowing the call to wait to time out after 1000ms and it never updated after even 2min after the workflow completed). Does anyone know why the state of the local java object representing the workflow isn't updating? Thanks in advance!

 

I understand that Adobe does not recommend launching workflows from within another workflow (it appears their reasoning is that creating Session objects is expensive).I understand that this also sounds like a use case for Multi-Resource-Support but that does not support Assets yet. I do not wish to bump up the number of allowed workflows for simultaneous launch as this is not only not recommended, but will bring the system to a crawl with the number of assets that might be regularly used (somewhere around 2k assets max but testing with synthetic loads of 5k assets).

 

TLDR: Workflow java object state does not reflect the actual state of the workflow instance. Why might this be happening?

1 Accepted Solution

Avatar

Correct answer by
Community Advisor
Because the Workflow object obtained from the WorkflowSession is a snapshot of the workflow state at the time it was retrieved. It does not automatically reflect changes to the underlying workflow instance.

View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor
Because the Workflow object obtained from the WorkflowSession is a snapshot of the workflow state at the time it was retrieved. It does not automatically reflect changes to the underlying workflow instance.

Avatar

Administrator

@rscott-sbux Did you find the suggestion helpful? Please let us know if you require more information. Otherwise, please mark the answer as correct for posterity. If you've discovered a solution yourself, we would appreciate it if you could share it with the community. Thank you!



Kautuk Sahni