2017-09-24 110 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