SSJS 中的 XPage Java 对象回收 [英] XPage Java Object Recycle in SSJS

查看:27
本文介绍了SSJS 中的 XPage Java 对象回收的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读有关回收 Domino 对象的建议:回收 Domino 的最佳方法是什么Java Beans 中的对象

I have read this suggestion about recycle of Domino objects: What is the best way to recycle Domino objects in Java Beans

如果我有一个名为 document 的数据源并且在此代码存在多次调用的函数中,最佳实践是什么:

What is best practice if I have a datasource named document and in a function that is called several times this code exists:

var doc=document.getDocument(true)

并对后端文档做一些事情.

and doing stuff to the backend document.

在我退出函数之前,我应该回收 doc 还是将我的后端文档回收到数据源?

Before I exit the function should I recycle doc or is my backend document to the datasource recycled then ?

推荐答案

这是一个很好的问题,因为这是回收一切"原则的唯一例外之一(另外两个值得注意的例子是你应该从不回收当前会话或数据库).回收数据源的后端文档是一个坏主意,因为 JSF 生命周期获得相同的句柄,并且您将从 Domino 下回收它.数据源会为我们处理这些,因此无需手动回收.另一方面,如果您获得了特定项目的句柄(即 doc.getFirstItem("someFieldName"),或作为日期的项目值,您应该回收这些对象,只是不是文档本身.

This is an excellent question, because this is one of the only exceptions to the "recycle everything" principle (two other notable examples are that you should never recycle the current session or database). It's a bad idea to recycle the back end document for a data source, because the JSF lifecycle gets the same handle, and you'd be recycling it out from under Domino. The data source takes care of this for us, so there's no need to recycle it manually. On the other hand, if you get a handle on specific items (i.e. doc.getFirstItem("someFieldName"), or item values that are dates, you should recycle those objects, just not the document itself.

到目前为止,回收 Java 和 SSJS 对象至关重要的最重要场景是视图迭代,因为每次前进到下一个条目或文档时,如果跳过回收,就会泄漏句柄.在大多数其他情况下,回收仍然是可取的,但更接近于可选,因为其他操作需要很长时间才能泄漏到足以引起问题的程度.但是,如果您要迭代一个非常大的视图,如果忘记回收,很容易在一次迭代中用完句柄.

By far the most important scenario where it's crucial to recycle Java and SSJS objects is in view iteration, because every time you advance to the next entry or document, you're leaking a handle if you skip the recycle. In most other cases, recycling is still advisable, but closer to being optional, because it takes a long time for other operations to leak enough to cause problems. But if you're iterating a very large view, you can easily run out of handles in a single iteration if you forget to recycle.

然而,有一个想法:我很少看到获取数据源后端文档的句柄是最佳方法的情况,因此我建议重新访问您的代码以确保甚至有必要获取此句柄开始.例如,不用 document.getDocument(true).getItemValueString("someFieldName"),只需调用 document.getValue("someFieldName").返回的值应该是相同的,但它会更有效地运行,并且您不会接触后端文档,因此回收不是问题.而且每次访问项目的输入次数都减少了,这肯定会随着时间的推移而增加.同样,用 document.setValue("someFieldName", "newValue") 代替 document.getDocument(true).replaceItemValue("someFieldName", "newValue").

One parting thought, however: I rarely see a situation where getting a handle on the back end document of a data source is the best approach, so I'd recommend revisiting your code to ensure that it's even necessary to obtain this handle to begin with. For instance, instead of document.getDocument(true).getItemValueString("someFieldName"), just call document.getValue("someFieldName"). The value returned should be identical, but it will run more efficiently, and you're not touching the back end document, so recycling isn't an issue. And it's less typing for every item access, which certainly adds up over time. Similarly, instead of document.getDocument(true).replaceItemValue("someFieldName", "newValue"), substitute document.setValue("someFieldName", "newValue").

这篇关于SSJS 中的 XPage Java 对象回收的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆