cancel
Showing results for 
Search instead for 
Did you mean: 

webscript synchronized problem

redybol2013
Champ in-the-making
Champ in-the-making
hello everyone:

I hvae meet a problem about execute a same webscrpit twice at the same time.
The second webscript executed when the first's unfinished.
The main job of the webscript is updating or creating node by a imported file.
Before the creating node, script will check the same name node existed or not.
only the unexisted condition that occuring the creating execution.

Here is the problem:
if the first webscript create a node named "AAA" and commit to the UserTransaction

(UserTransaction transaction = serviceRegistry.getTransactionService().getUserTransaction())

then the second webscript also need to create node "AAA",
but this time, the exeisting check of second webscript is uneffected.
so the second webscript will occure a DuplicateChildNodeNameException;
   "org.alfresco.service.cmr.repository.DuplicateChildNodeNameException: Duplicate child name not allowed: AAA"

so will  webscript synchronize data before it finished the executing?

so is anyone have faced the problem like this before?
Thanks for the help first~
1 REPLY 1

iblanco
Confirmed Champ
Confirmed Champ
As you state the problem seems to be that your second transaction does not see the new node because it was created in a parallel transaction so it tries to create it and throws a duplicaChildNodeNameException.

Alfresco has a <a href="http://wiki.alfresco.com/wiki/Java_Foundation_API#Using_RetryingTransactionHelper" target="_blank">RetryingTransactionHelper</a> that could make your code retry in case of a failure like this. But keep those things in mind:

1.- Call <a href="http://dev.alfresco.com/resource/docs/java/repository/org/alfresco/repo/transaction/RetryingTransact...(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback, boolean, boolean)">doInTransaction</a> so that a new transaction is used, otherwise you won't see the new node in the second attempt either.
2. - Only some <a href="http://svn.alfresco.com/repos/alfresco-open-mirror/alfresco/HEAD/root/projects/repository/source/jav...">exceptions classes</a> cause retrying,so you might have to capture DuplicateChildNodeNameException and rethrow it as one of those exceptions.

Good luck