I am Reading Some Large XML files and Storing them into Database. It is arond 800 mb.
It stores many records and then terminates and gives an exception:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.util.IdentityHashMap.resize(Unknown Source)
at java.util.IdentityHashMap.put(Unknown Source)
Using Memory Analyzer i have created .hprof files which says:
76,581 instances of "java.lang.String", loaded by "<system class loader>" occupy 1,04,34,45,504 (98.76%) bytes.
Keywords
java.lang.String
I have setters and getters for retrieving values.How do i resolve this issue. Any help would be appreaciated.
I have done with increasing memory through JRE .ini. but problem doesn't solved
EDIT: I am using scireumOpen to read XML files.
Example code i have used:
public void readD() throws Exception {
XMLReader reader = new XMLReader();
reader.addHandler("node", new NodeHandler() {
@Override
public void process(StructuredNode node) {
try {
obj.setName(node
.queryString("name"));
save(obj);
} catch (XPathExpressionException xPathExpressionException) {
xPathExpressionException.printStackTrace();
} catch (Exception exception) {
exception.printStackTrace();
}
}
});
reader.parse(new FileInputStream(
"C:/Users/some_file.xml"));
}
public void save(Reader obj) {
try {
EntityTransaction entityTransaction = em.getTransaction();
entityTransaction.begin();
Entity e1=new Entity;
e1.setName(obj.getName());
em.persist(e1);
entityTransaction.commit();
} catch (Exception exception) {
exception.printStackTrace();
}
}