2017-09-24 47 views
0

运行时,我的系统上运行的斯坦福CoreNLP它似乎并没有清空内存后不是空的内存。 即使使用当线程...
我有2班Testx.java(包含主线程)& Testx2.java实现Runnable。

我想这样做是对的字符串没有运行斯坦福CoreNLP后完全清空内存。 1,如下面的代码所示...

而且我知道这是可以做到!因为我已经看到了内存使用浸之前,它工作时(但我没有保持备份的代码:/)
VM参数是-Xmx2048m斯坦福大学CoreNLP确实对线程

public class Testx { 
    public static void main(String[] args) { 

    String text = "If you had to guess the top city for entertainment & media your first thought would probably be LA."; 

    Textx2 x = new Textx2(text); 
    Thread t1 = new Thread(x); 
    t1.run(); 
    t1.interrupt(); 

Memory usage after t1 has finished
//如何在转移到下一个字符串之前完全清空这里的内存?

String text2 = "Taylor Swift has a certain attachment to the number 1989 it's the year of her birth."; 

    Textx2 x2 = new Textx2(text2); 
    Thread t2 = new Thread(x2); 
    t2.run(); 
    t2.interrupt(); 
} 

Testx2.java代码。

String text; 

public Textx2(String text) { 
    this.text = text; 
} 

@Override 
public void run() { 

      Properties props = new Properties(); 
      Annotation document = new Annotation(text); 
      props.put("annotators", "tokenize, ssplit, pos, lemma, ner, parse, depparse, sentiment, mention, dcoref, natlog, relation, entitymentions, openie"); 
      StanfordCoreNLP pipeline = new StanfordCoreNLP(props); 
      pipeline.annotate(document); 

} 

java memory usage

回答

0

尝试运行此行两个线程完成后:

StanfordCoreNLP.clearAnnotatorPool(); 
+0

要添加到这一点:注释都存储在'SoftReference's,这意味着它们会显示为已用内存,他们会在程序遇到OOM错误之前收集垃圾。 –

+0

@StanfordNLPHelp StanfordCoreNLP.clearAnnotatorPool();会删除管道!再次实例化它将需要更多的内存。尝试把2个线程在同时**(真)**循环,并检查内存使用情况将如何发展? – InternetOfThings

+0

@GaborAngeli我以**文本1 ** ** **文本2从包含1000数据库(长)字符串。我把它们放在** while(true)循环**中,并在每个循环上运行管道。当获得一个非常大的字符串时会发生什么?在't1.run();之后t1.interrupt();'在线程t2开始之前,带注释的字符串会被垃圾收集吗? 另外我正在使用16GB的RAM – InternetOfThings