Page 1 of 1

Thread safe addTargetPath

PostPosted: Tue Sep 22, 2015 7:09 am
by roded
Hi,
I'd like to add a cached Part to several other Parts in a thread-safe manner.
The only possible method I've found is using addTargetPart(sourcePart) which, I understand it, does some (minor) manipulations on the source Part, which I'd like to avoid (due to theoretical thread-safety and garbage collection issues).
Is there a way to add the cached Part without changing it?
I could of course clone the entire package, but that would result in an unnecessary performance hit which is rather important to this case.
Any pointers would be much obliged.
Thanks,
Roded.

Re: Thread safe addTargetPath

PostPosted: Wed Sep 30, 2015 10:47 am
by jason
the source part is the existing part in the docx, to which you are adding the target part (the target part is the target of a new rel, which is added to the source part's rels part).

the changes to the source part (using method setPartShortcut) could be avoided.

but the changes to the source part's rels part are of course, important.

the method RelationshipsPart.addPart which does the work calls loadPart, which sets some fields on the TARGET part. so you should invoke addTargetPart on a clone of the part. (You don't need to clone the package). Does/could the target part reference related parts in your use case?

Re: Thread safe addTargetPath

PostPosted: Tue Oct 06, 2015 6:53 pm
by roded
Hi Jason, thanks for your reply.
The target part should not reference other related parts (at least as of now).
It could very well be that I'm asking for the impossible, but the cloning of the target part is an expensive operation I'd like to avoid if possible.
Is the target.setOwningRelationshipPart() & target.setPackage() calls of loadPart() mandatory for the correct saving of a package which contains such an added target parts?
Thanks,
Roded