简体   繁体   English

Stanford-CoreNLP在线程上运行后不会清空内存

[英]Stanford-CoreNLP doesn't empty Memory after running on Threads

While running Stanford CoreNLP on my system it doesn't seem to empty the memory. 在我的系统上运行Stanford CoreNLP时,似乎没有清空内存。 Even when using Threads... 即使使用线程...
I have 2 classes Testx.java (Contains main thread) & Testx2.java which implements Runnable. 我有2个类Testx.java (包含主线程)和Testx2.java ,它实现了Runnable。

What I would like to do is to empty the memory completely after running the Stanford CoreNLP on String no. 我想做的是在字符串No上运行Stanford CoreNLP之后完全清空内存。 1 as shown in the code below... 1如下代码所示...

And I know it can be done! 而且我知道可以做到! Because I have seen the Memory usage dip while working on it before(But I didn't keep a back up of that code! :/) 因为我以前在处理它时已经看到内存使用率下降了(但是我没有备份该代码!:/)
VM Arguments is -Xmx2048m 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 t1完成后的内存使用情况
// How do I Completely empty the Memory Here before moving on to the next String? //在继续下一个字符串之前,如何完全清空此处的内存?

    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 Code. 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 Java内存使用

在两个线程都完成之后,尝试运行此行:

StanfordCoreNLP.clearAnnotatorPool();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM