Feature #1752
eliminate statics/singleton patterns in all TRPL worker classes and other dependent Java code
0%
Related issues
History
#1 Updated by Greg Shah over 13 years ago
- Target version set to Code Improvements
#2 Updated by Greg Shah over 9 years ago
- Target version changed from Code Improvements to TRPL 2.0
- Estimated time changed from 40.00 to 80.00
#3 Updated by Greg Shah about 1 year ago
- Related to Feature #3211: implement multi-threaded pattern engine and rework the ConversionDriver to leverage it added
#4 Updated by Greg Shah about 1 year ago
- Subject changed from eliminate statics/singleton patterns in pattern engine/symbol resolver and other related classes to eliminate statics/singleton patterns in all TRPL worker classes and other dependent Java code
#5 Updated by Greg Shah about 1 year ago
- Target version deleted (
TRPL 2.0) - Assignee set to Octavian Adrian Gavril
#6 Updated by Octavian Adrian Gavril about 1 year ago
- Status changed from New to WIP
#7 Updated by Octavian Adrian Gavril about 1 year ago
com.goldencode.p2j.schema.ImportWorker$SqlRecordLoadercom.goldencode.p2j.convert.NameMappingWorker$ProgramInfocom.goldencode.p2j.convert.NameMappingWorker$MethodInfocom.goldencode.p2j.uast.CallGraphWorker$CallSiteHintcom.goldencode.p2j.convert.BufferScopeWorkercom.goldencode.p2j.convert.DatabaseReferenceWorkercom.goldencode.p2j.convert.ExpressionConversionWorkercom.goldencode.p2j.convert.I18nWorkercom.goldencode.p2j.convert.IndexSelectionWorkercom.goldencode.p2j.convert.NameConverterWorkercom.goldencode.p2j.convert.NameMappingWorkercom.goldencode.p2j.convert.UnreachableCodeWorkercom.goldencode.p2j.pattern.FileOperationsWorkercom.goldencode.p2j.pattern.TemplateWorkercom.goldencode.p2j.persist.orm.DDLGeneratorWorkercom.goldencode.p2j.preproc.PreprocessorHintsWorkercom.goldencode.p2j.report.ReportWorkercom.goldencode.p2j.schema.DataModelWorkercom.goldencode.p2j.schema.DmoAsmWorkercom.goldencode.p2j.schema.ImportWorkercom.goldencode.p2j.schema.P2OAccessWorkercom.goldencode.p2j.schema.SchemaWorkercom.goldencode.p2j.uast.CallGraphWorkercom.goldencode.p2j.uast.JavaPatternWorkercom.goldencode.p2j.uast.ProgressPatternWorkercom.goldencode.p2j.uast.UastHintsWorkercom.goldencode.p2j.xml.XmlPatternWorker
#8 Updated by Constantin Asofiei about 1 year ago
If you look at DataModelWorker, you will see the static state is in a WorkArea class, to be context-local. This (and other pattern classes) were changed like this, to allow runtime conversion of queries; other classes which are not yet changed I think should move to the same context-local approach.
#9 Updated by Octavian Adrian Gavril about 1 year ago
Constantin Asofiei wrote:
If you look at
DataModelWorker, you will see the static state is in aWorkAreaclass, to be context-local. This (and other pattern classes) were changed like this, to allow runtime conversion of queries; other classes which are not yet changed I think should move to the same context-local approach.
Got it. So, I need to move all the static variables (shared data) into a WorkArea inner class that ensures thread safety for all the workers used in TRPL.
#10 Updated by Octavian Adrian Gavril about 1 year ago
Should static methods be kept or make them non-static and use them through a class instance?DataModelWorker:
- XmlPatternWorker.createAst(XmlTokenTypes.CONTENT, schema + ".impl", elAttr);
+ context.get().xpw.createAst(XmlTokenTypes.CONTENT, schema + ".impl", elAttr);
}
this.schemaElem = schemaElem;
@@ -1101,7 +1102,7 @@
while (attr != null)
{
String key = attr.getText();
- String value = XmlPatternWorker.getAttributeValue(attrs, key);
+ String value = context.get().xpw.getAttributeValue(attrs, key);
info.putAttribute(key, value);
@@ -1342,5 +1343,7 @@
private static class WorkArea
{
/** Root of the target tree currently being processed (created). */
private DataModelAst root = null;
+
+ private final XmlPatternWorker xpw = new XmlPatternWorker();
}
}#11 Updated by Greg Shah about 1 year ago
There is nothing intrinsically unsafe with static methods. Any state they access will need to be context local OR synchronized/protected to be thread-safe.
#12 Updated by Octavian Adrian Gavril about 1 year ago
I went through all the workers listed above and checked where the variables are good to store in the context-local. I ignored all the constants or immutable lists, as they are populated in a static block and then just referenced. Most of the workers were in this situation, having logs or constants. I made these changes in the task branch 1752a/15886.