Skip to content

Commit d1a8e20

Browse files
committed
Some performance improvements for JAXBPrettyConfigParser
1 parent a862428 commit d1a8e20

1 file changed

Lines changed: 18 additions & 9 deletions

File tree

‎core/src/main/java/com/ocpsoft/pretty/faces/config/JAXBPrettyConfigParser.java‎

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,32 +38,41 @@ public class JAXBPrettyConfigParser implements PrettyConfigParser
3838

3939
private final static String JAXB_CLASS_PACKAGE = "com.ocpsoft.pretty.faces.config.types";
4040

41-
private JAXBContext jaxbContext;
42-
43-
private SAXParserFactory saxParserFactory;
41+
private final static JAXBContext jaxbContext;
42+
43+
private final SAXParserFactory saxParserFactory;
4444

4545
private Schema schema;
4646

4747
/**
48-
* Constructor
48+
* We do this expensive operations here. This should
49+
* be OK as we do it once per ClassLoader.
4950
*/
50-
public JAXBPrettyConfigParser()
51+
static
5152
{
5253
try
5354
{
5455
// build JAXBContext using the package we generate the classes to
5556
jaxbContext = JAXBContext.newInstance(JAXB_CLASS_PACKAGE);
5657

57-
// create a namespace aware SAXParserFactory
58-
saxParserFactory = SAXParserFactory.newInstance();
59-
saxParserFactory.setNamespaceAware(true);
60-
6158
}
6259
catch (JAXBException e)
6360
{
6461
throw new IllegalStateException(e);
6562
}
6663
}
64+
65+
/**
66+
* Creates a new {@link JAXBPrettyConfigParser}
67+
*/
68+
public JAXBPrettyConfigParser()
69+
{
70+
71+
// SAXParserFactory is NOT thread-safe
72+
saxParserFactory = SAXParserFactory.newInstance();
73+
saxParserFactory.setNamespaceAware(true);
74+
75+
}
6776

6877
/*
6978
* @see

0 commit comments

Comments
 (0)