Hi,
I am writing a helper class which provides various static method to parse XML and return Document etc. This helper class will be called by several programs.
Here the snippet:
public class MyParser {
public static Document parse(
String xmlString) throws SAXException, IOException {
InputSource in = new InputSource(new StringReader(xmlString));
DOMParser parser = new DOMParser();
parser.parse(in);
return parser.getDocument();
}
//....
}
Now my question is that whether I can declare DOMParser also as a static member variable and do not instantiate every time?
public class MyParser {
private static DOMParser parser = new DOMParser();
public static Document parse(String xmlString) throws SAXException, IOException {
InputSource in = new InputSource(new StringReader(xmlString));
parser.parse(in);
return parser.getDocument();
}
//....
}
I could not understand if it will have any adverse impact?
Thanks.
Sam