I need to browse through around 3000 folders, each folder contains 300 CSV files.
This is the error that occurs at line while ((nextLine=csvReader.readNext()) != null)
:
Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded
at au.com.bytecode.opencsv.CSVParser.parseLine(CSVParser.java:206)
at au.com.bytecode.opencsv.CSVParser.parseLineMulti(CSVParser.java:174)
at au.com.bytecode.opencsv.CSVReader.readNext(CSVReader.java:237)
at DA.readTelemetryData(DA.java:78)
at DA.main(DA.java:24)
The question is how to solve this issue? Why does it occur and what is wrong in my code?
Here I provide the code:
private static HashMap<Integer,HashMap<Integer,List<double[]>>> readTelemetryData() throws Exception
{
HashMap<Integer,HashMap<Integer,List<double[]>>> xy_total = new HashMap<Integer,HashMap<Integer,List<double[]>>>();
for (int i=0; i<Constants.MAX_FOLDERS; i++)
{
HashMap<Integer,List<double[]>> xy_total_per_folder= new HashMap<Integer,List<double[]>>();
for (int j=0; j<Constants.MAX_FILES_INSIDE_FOLDER; j++)
{
CSVReader csvReader = null;
File f = new File("data/"+ (i+1) +"/"+ (j+1) +".csv");
if(f.exists())
{
csvReader = new CSVReader(new FileReader(f));
List<double[]> xyArr = new ArrayList<double[]>();
String[] firstLine=csvReader.readNext();
if (firstLine != null)
{
String[] nextLine=null;
while ((nextLine=csvReader.readNext()) != null)
{
double[] d = new double[2];
d[0]=Double.parseDouble(nextLine[0]);
d[1]=Double.parseDouble(nextLine[1]);
xyArr.add(d);
}
}
xy_total_per_folder.put(j, xyArr);
csvReader.close();
}
}
xy_total.put(i, xy_total_per_folder);
}
return xy_total;
}