AnsweredAssumed Answered

behaviour threading doesn't make sense

Question asked by aweber1nj on Jul 17, 2012
Latest reply on Jul 17, 2012 by mrogers
I am baffled as to how to synchronize methods in a behaviour class.  I have read everything I can find about ejb and spring beans.  The EJB3 annotations don't work (or aren't obeyed).  And from what I can tell, I should be able to use traditional "synchronized" blocks within the class, but they keep halting everything.

I'm using some Alfresco code I found to check if the parent folder has the "Countable" aspect.  If not, add it and set the counter to 1.  If it does, try and increment the counter using nodeService.setProperty().

The main problem is when you upload multiple objects at once, a second (or third) thread seems to start before the first one completes (log4j shows the thread names).  Alfresco doesn't like that, because the write/update of the parent folder (which would be the same parent for all the remaining objects being uploaded and updated at this time) causes a block/deadlock situation as subsequent threads try to read the parent's properties (and they, too, may update the folder).

So basically the code works great if you only upload one document at a time.  I can't find a locking (not transaction) construct to put anywhere that'll let me synchronize access to the parent, and keep things moving at all.

I'm sure this kind of thing has been addressed.  Can someone please help me figure out how to synchronize this code?  It's the only thing I can think of that Alfresco is complaining about right now…and I'm a little surprised it is at all.  It's not like I'm testing with 10 or 100 concurrent users.  I'm just testing an import of 2 documents at a time and I am not allowed to put any concurrency constructs in the code! :(

Outcomes