【发布时间】:2017-09-24 13:39:58
【问题描述】:
在我的系统上运行 Stanford CoreNLP 时,它似乎并没有清空内存。
即使使用线程...
我有 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 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 eclipse multithreading memory-management stanford-nlp