Details
-
Improvement
-
Status: Closed
-
Major
-
Resolution: Fixed
-
Jena 3.14.0
-
None
Description
This is a follow up to JENA-1861 which is about the thread safety of Query objects. As sharing a Query object across threads may introduce race conditions, the obvious workaround would be to just clone it. However, the current implementation serializes the query to string and then re-parses it which causes a very high overhead (for my use case it became the top entry in the VisualVM profiler).
Proposal:
- Extend ElementTransformCopyBase with a 'alwaysCopy' flag analogous to ExprTransformCopy
- Add a new constructor to ExprTransformApplyElementTransform(ElementTransform transform, boolean alwaysCopy) so that the alwayCopy flag of the underlying ExprTransformCopy can be set to true
- Implement clone using syntatic transforms as below
public static Query fastClone(Query query) { ElementTransform eltXform = new ElementTransformCopyBase2(true); ExprTransform exprXform = new ExprTransformApplyElementTransform2(eltXform, true); Query result = QueryTransformOps.transform(query, eltXform, exprXform); return result; }
This approach 'works-for-me' and I can create a pull request for this, but maybe there are more subtleties to the outlined approach that need to be considered?
Attachments
Issue Links
- relates to
-
JENA-1935 Query::cloneQuery produces invalid syntax
- Closed
- links to