在我的系统上运行Stanford CoreNLP时,它似乎没有清空内存。
即使使用Threads ...
我有2个类 Testx.java (包含主线程)& Testx2.java 哪个
实现Runnable。
我想要做的是在String no上运行Stanford CoreNLP之后完全清空内存。 1,如下面的代码所示......
我知道可以做到!因为我之前在使用它时看到了内存使用率下降(但我没有备份该代码!:/)
VM参数为-Xmx2048m
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之前完全清空Memory Here?
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);
}
答案 0 :(得分:0)
在两个线程完成后尝试运行此行:
StanfordCoreNLP.clearAnnotatorPool();