2017-09-24 12 views
0

私のシステムでStanford CoreNLPを実行している間はメモリを空にしていないようです。 スレッドを使用していても...
は、私は2クラスTestx.java(メインスレッドを含みます) はRunnableを実装して& Testx2.javaを持っています。

私がしたいのは、Stanford CoreNLPをString noで実行した後にメモリを完全に空にすることです。 1の下のコードに示すように...

そして私はそれができることを知っている!前にそれに取り組んでいる間、私はメモリ使用量のディップを見てきましたので(しかし、私は戻ってそのコードの追いついていなかった!:/)
VM引数は-Xmx2048mですStanford-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();パイプラインを削除します!再度インスタンシエートするとメモリが増えます。 ** while(true)**ループに2つのスレッドを入れて、メモリ使用量がどのように増加するかを確認してください。 – InternetOfThings

+0

@GaborAngeli私は1000sを含むデータベースから** text1 **&** text2 **を取りますの(長い)文字列。私はそれらを** while(真の)ループ**に入れて、パイプラインをそれぞれ実行しています。非常に大きな文字列が得られたらどうなりますか? 't1.run();の後。 t1.interrupt(); 'Annotated Stringはスレッドt2を起動する前にガベージコレクションを行いますか? また、16GBのRAMで作業しています – InternetOfThings