Skip to content

oom caused by parallel() #32

@xueding-e

Description

@xueding-e

this issues occurs when i calculate array size,
this array about three minion arays,i hava 2G heap.this file is only 40m,and if i use no parallel,this
program only uses 50m, Ask,what's the cause

static void useStream(){
    long uniqueWord = 0;
    try (Stream<String> lines =
                 Files.lines(Paths.get("D:\\nlp\\dictionary\\CoreNatureDictionary.ngram.txt"), Charset.defaultCharset())){
        long start = System.currentTimeMillis();
        uniqueWord = lines.flatMap(line -> Arrays.stream(line.split(" "))).parallel().distinct().count();

// uniqueWord = lines.flatMap(line -> Arrays.stream(line.split(" "))).distinct().count();
System.out.println(uniqueWord);
long end = System.currentTimeMillis();

        System.out.println( (end-start)+"ms");
    }catch (IOException e){
        e.printStackTrace();
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions