1
votes

I am using workflow to copy lots of pdfs from one location to other dam locations based on the data and set of requirements. I am using the following code Asset damAsset = manager.createAsset(path, is, mimeType,true); where path is the destination dire and 'is' is inputstream pdf file, there is no metadata on I am applying the metadata to destination file using following statement Node node = damAsset.adaptTo(Node.class); Node mdNode = node.getNode("jcr:content/metadata"); mdNode.setProperty("pttitle", forms.getFileDisplayTitle()); Once all the files are finished I am terminating the workflow uing workflowSession.terminateWorkflow(workItem.getWorkflow());

Workflow works fine for most of the time but last file didn't set with the metadata due to following exception. This exception happens randomly once after running repeatedly for 3-4 times.

javax.jcr.InvalidItemStateException: Unable to update a stale item: item.save()
at org.apache.jackrabbit.core.ItemSaveOperation.perform(ItemSaveOperation.java:262)
at org.apache.jackrabbit.core.session.SessionState.perform(SessionState.java:216)
at org.apache.jackrabbit.core.ItemImpl.perform(ItemImpl.java:91)
at org.apache.jackrabbit.core.ItemImpl.save(ItemImpl.java:329)
at org.apache.jackrabbit.core.session.SessionSaveOperation.perform(SessionSaveOperation.java:65)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.apache.jackrabbit.core.state.StaleItemStateException: 1f6fc642-1a20-4cac-abe5-70f903aefde4 has been modified externally
at org.apache.jackrabbit.core.state.SharedItemStateManager$Update.begin(SharedItemStateManager.java:679)
at org.apache.jackrabbit.core.ItemSaveOperation.perform(ItemSaveOperation.java:258)
2

2 Answers

1
votes

stale item exceptions occur when there is another session on another thread that has updated the item in question. i.e. Something else saved before you did.

details on this can be found: http://wiki.apache.org/jackrabbit/ItemStateManagement

I would check to see if there are any other DAM related workflows occurring at the same time that you are doing yours.

0
votes

I am experiencing the same behavior at this moment. I found this Bug from JackRabbit related to StaleItemStateException:

JCR-2908

Hope it is useful, at least to get some idea