【问题标题】:XPages: how to recycle Domino objects when using a ViewEntryCollection several times?XPages:多次使用 ViewEntryCollection 时如何回收 Domino 对象?
【发布时间】:2015-06-24 00:18:54
【问题描述】:

我试图找到一个类似的问题,但我没有成功。

在一个 bean 中,我多次循环 ViewEntryCollection,添加或删除条目。有人可以告诉我确切的时间这些物品应该被回收吗?我希望能够重复使用整个集合,所以我不想破坏我可能仍然需要的任何对象。

我的代码:

public static int FTSearchAll(ViewEntryCollection vec, View vw, String cat, String query) throws NotesException {
    ...
    for (ViewEntry ve = nav.getFirst(); ve != null; ) {
        ViewEntry next = nav.getNext(ve);
        Document doc = ve.getDocument();
        if (doc == null)
            continue;
        try {
            Vector v = session.evaluate(query, doc);
            if (v != null && v.size() > 0 && (Double) v.elementAt(0) != 0) {
                vec.addEntry(ve, false);
            } else {
                for (ViewEntry dce = vec.getFirstEntry(); dce != null;) {
                    ViewEntry dcnext = vec.getNextEntry(dce);
                    if (dce.getNoteID().equals(ve.getNoteID())) {
                        vec.deleteEntry(dce);
                        incinerate(dce);
                        break;
                    }
                    dce = dcnext;
                }
            }
        } catch (NotesException ne) {

        } finally {
            incinerate(ve, doc);
        }
        ve= next;
    }

一如既往:谢谢!

【问题讨论】:

    标签: java xpages javabeans lotus-domino recycle


    【解决方案1】:

    规则很简单:当指向 Notes C 对象的 Java 对象即将进入垃圾堆时,必须调用 .recycle()。 因此,您需要对循环内的所有条目执行此操作。 我的小经验法则:创建 Notes Java 对象的块(想想 { ... } )必须在最后调用它的 .recycle() 函数。 省去很多麻烦

    【讨论】:

      【解决方案2】:

      我看到了这个,但不完全确定我是否遗漏了什么或代码保留了它的功能......:S

          for (ViewEntry ve = nav.getFirst(); ve != null; ) {         
      
              ViewEntry next = nav.getNext(ve);
              Document doc = ve.getDocument();
      
              if (doc == null) {
                  incinerate(ve);             // << new
                  ve = next;                  // << new
                  continue;               
              }
      
              try {           
      
                  Vector v = session.evaluate(query, doc);
                  if (v != null && v.size() > 0 && (Double) v.elementAt(0) != 0) {
                      vec.addEntry(ve, false);
                  } else {
                      for (ViewEntry dce = vec.getFirstEntry(); dce != null;) {
      
                          ViewEntry dcnext = vec.getNextEntry(dce);
                          if (dce.getNoteID().equals(ve.getNoteID())) {
                              vec.deleteEntry(dce);
                              incinerate(dce, dcnext);       // << new                    
                              break;
                          }
                          incinerate(dce);                // << new
                          dce = dcnext;
      
                      }
                  }
      
              } catch (NotesException ne) {
      
              } finally {             
                  incinerate(ve, doc);                
              }
      
              ve = next;
          }
      

      也许检查另一个实现会更好。

      无论如何,我建议您使用 OpenNTF Domino API 并摆脱循环,您还将获得对条目的适当迭代: http://www.openntf.org/main.nsf/project.xsp?r=project/OpenNTF%20Domino%20API

      【讨论】:

      • 天啊,OpenNTF Domino 库...谢谢,我真的不知道它不需要回收...让我觉得有点愚蠢... :-$ 我想我'我会尝试说服我的客户采用这个 API。
      • 该库中 ViewEntryCollection 类的小(大)问题:当您必须删除条目时没有正确的方法来使用它(NullPointerException)。
      猜你喜欢
      • 2012-06-04
      • 1970-01-01
      • 1970-01-01
      • 2018-11-08
      • 1970-01-01
      • 1970-01-01
      • 2017-12-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多