public class Functions {
public Functions (){
}
Map<String, Set<String>> task() throws Exception{
System.out.println("start reading for strain file");
String value= "/home/charles/Documents/mmp.txt";
File file = new File(value);
FileInputStream fin = new FileInputStream(file);
FileChannel fc = fin.getChannel();
MappedByteBuffer mapByteBuff = fc.map(FileChannel.MapMode.READ_ONLY, 0, file.length());
byte[] buffer= new byte[(int)fc.size()];
mapByteBuff.get(buffer);
BufferedReader br=new BufferedReader(new InputStreamReader(new ByteArrayInputStream(buffer)));
Map<String, Set<String>> strainHashMap = new HashMap<String, Set<String>>(824*12+1,2);
String line = br.readLine();
// String delim="[\t]";
String[] tokens=new String[3];
// String delim="[\t]";
for (line = br.readLine(); line != null; line = br.readLine()) {
// tokens=new String[3];
tokens=line.split("[\t]",3);
//here is where I am stuck.. I get java out of heap memory
Set<String> strainSet = strainHashMap.get(tokens[1]);
if(strainSet==null){
strainSet = new HashSet<String>();
strainSet.add(tokens[2]);
strainHashMap.put(tokens[1],strainSet);
}
else{
strainSet.add(tokens[2]);
strainHashMap.put(tokens[1], strainSet);
}
if(strainHashMap.size() % 600000 ==0){
System.out.println("strain"+strainHashMap.size());
}
if(strainHashMap.size() % 610000 ==0){
System.out.println("strain"+strainHashMap.size());
}
if(strainHashMap.size() % 620000 ==0){
System.out.println("strain"+strainHashMap.size());
}
if(strainHashMap.size() % 650000 ==0){
System.out.println("strain"+strainHashMap.size());
}
if(strainHashMap.size() % 700000 ==0){
System.out.println("strain"+strainHashMap.size());
}
if(strainHashMap.size() % 851000 ==0){
System.out.println("strain"+strainHashMap.size());
}
}
fc.close();
fin.close();
System.out.println("The hash stain is " + strainHashMap.size());
// System.out.println("The Genotype is " + mapGenotype.size());
System.out.println("moving out of strain function");
return strainHashMap;
}
public Map<String, Genotype> genotype() throws Exception {
// TODO Auto-generated method stub
System.out.println("entering genotype data function");
// TODO Auto-generated method stub
String value= "/home/charles/Documents/mmp.txt";
File file = new File(value);
FileInputStream fin = new FileInputStream(file);
FileChannel fc = fin.getChannel();
MappedByteBuffer mapByteBuff = fc.map(FileChannel.MapMode.READ_ONLY, 0, file.length());
byte[] buffer= new byte[(int)fc.size()];
mapByteBuff.get(buffer);
BufferedReader br=new BufferedReader(new InputStreamReader(new ByteArrayInputStream(buffer)));
Map<String, Genotype> mapGenotype = new HashMap<String, Genotype>(824*12+1,2);
String line = br.readLine();
// String delim="[\t]";
String[] tokens=new String[8];
// String delim="[\t]";
for (line = br.readLine(); line != null; line = br.readLine()) {
tokens=new String[8];
tokens=line.split("[\t]",8);
// tokens=line.split(delim);
// Genotype genotypeObject = new Genotype();
// genotypeObject.setChromsomeName(tokens[3]);
// genotypeObject.setMutation(tokens[6]);
// genotypeObject.setPosition(Double.parseDouble(tokens[4]));
//genotypeObject.setPosition(Double.parseDouble(tokens[4]));
// genotypeObject.setRef(tokens[5]);
if(!mapGenotype.containsKey(tokens[1])){
Genotype genotypeObject = new Genotype();
genotypeObject.setChromsomeName(tokens[3]);
genotypeObject.setMutation(tokens[6]);
genotypeObject.setPosition(Double.parseDouble(tokens[4]));
//genotypeObject.setPosition(Double.parseDouble(tokens[4]));
genotypeObject.setRef(tokens[5]);
mapGenotype.put(tokens[1], genotypeObject);
}
if(mapGenotype.size() % 700000 ==0){
System.out.println(mapGenotype.size());
}
if(mapGenotype.size() % 650000 ==0){
System.out.println(mapGenotype.size());
}
if(mapGenotype.size() % 851000 ==0){
System.out.println(mapGenotype.size());
}
}
fc.close();
fin.close();
System.out.println("leaving Genotype method of function");
return mapGenotype;
}
}
It is strange that I run out of memory after hash map has added 650000 values in task method. I run a same method with similar file and it works perfectly fine genotype.
I am using jdk 1.6
Ubuntu 12.04, Eclipse kepler.
The .ini file has -XX:MaxPermSize=256m -Xms740m -Xmx1412m
The Run as configuration are as below: -Xms912m -Xmx2124m Swap memory is more than 3.5 gb.
I was able to do this task sometime back, but unfortunately, lost all my data and am trying to set all this up again. I have put huge number of hours to fix this, but nothing seems to help.
This is the Error I get: Exception in thread "main" java.lang.OutOfMemoryError: Java heap space