memory - java.lang.OutOfMemoryError: Java heap space creating a long list of Myclass -


i'm parsing data internet create arraylist every politician class has field hashmap. every hashmap contains 132*150 entry. after 164th map filled got exception: java.lang.outofmemoryerror: java heap space. wanted store big list using serialization use in future. how should proceed? should serialize politician instances , not whole list? there other optimal way store data? (if needed) i'm writing data files. thinked store data "as object" improve ease of use. code:

private static void setvotiparlamentari(parseropenparlamento parser, arraylist<politician> politicianlist){ for(politician p : politicianlist){     string filepath = system.getproperty("user.dir") + file.separator + "io_files" + file.separator + "info_parlamentari2";     string filename = file.separator + p.getname() + ".txt";     iterator<string> votesiterator = parser.parsepoliticianvotes(p).iterator();     filewriter w = null;     try {         w = new filewriter(filepath+filename);     } catch (ioexception e) {         e.printstacktrace();     }     printwriter wr = new printwriter(new bufferedwriter(w));     while (votesiterator.hasnext()){         string vote = votesiterator.next();         // i.e. string vote = 35521:08/11/2016:favorevole:scci-maie favorevole:approvata:391         string tokens[] = vote.split(parser.getsplittingchar());         string idvote = tokens[0];         string datevot = tokens[1];         string politicianvote = tokens[2];         string groupvote = tokens[3];         string result = tokens[4];         string difference = tokens[5];         wr.write(idvote+":"+datevot+":"+politicianvote+":"+groupvote+":"+result+":"+difference+system.getproperty("line.separator"));         p.getvotazioni().put(integer.parseint(idvote), new votazione(idvote, datevot, politicianvote, groupvote, result, difference));     }     wr.close(); } 

}

if use eclipse ide:

right mouse click on run - run configuration - arguments - vm arguments, add (for increment java heap memory size, choose other value)

-xmx2048m 

if use command line, add tail:

-xmx2048 

(2048 maximum size of heap memory, choose other value)


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -