0

我计划对所有 5 分钟的 xAgent 使用单个入口点,这意味着一个 XPage 会启动所有 5 分钟的“java 代理”(应该每 5 分钟启动一次的类)。我想在新的不同线程中启动该 java 代码,以便真正并行启动此类代理。

提到的“java 代理”与其他 NSF 应用程序类具有很强的相互依赖性。其中许多依赖于 FacesContext 和/或其他 XSP/JSF 全局变量。

“Java 代理”代码示例:

import javax.faces.context.FacesContext;
import com.ibm.domino.xsp.module.nsf.NSFComponentModule;
import com.ibm.domino.xsp.module.nsf.NotesContext;
import com.ibm.xsp.extlib.util.ExtLibUtil;

public class Agent1 implements Runnable {

private NSFComponentModule module;

public Agent1() {
    this.module = NotesContext.getCurrent().getModule();
    System.out.println("Agent1: test 1.1: " + (ExtLibUtil.getCurrentSessionAsSigner() == null)); // FALSE here
    System.out.println("Agent1: test 1.2: " + (FacesContext.getCurrentInstance() == null)); // FALSE here
}

public void run() {
    NotesContext context = new NotesContext(this.module);
    NotesContext.initThread(context);

    System.out.println("Agent1: test 2.2: " + (ExtLibUtil.getCurrentSessionAsSigner() == null)); // TRUE here
    System.out.println("Agent1: test 2.2: " + (FacesContext.getCurrentInstance() == null)); // TRUE here

    // Threaded xAgent job here...

    NotesContext.termThread();
}
}

问题:此类方法如:FacesContext.getCurrentInstance()、ExtLibUtil.getCurrentSessionAsSigner() 在新线程中返回 NULL。

问题:是否可以在新线程中初始化 XSP / JSF 引擎以访问 FacesContext 等(在“Agent1:test 2.1”和“Agent1:test 2.2”行中获取不为空)?

提前致谢!

4

1 回答 1

0

在 OpenNTF Domino API 中使用 XOTS 进行开发时,我遇到了类似的问题。最好的选择是传递构造函数中需要的任何对象。这是有关 XOTS http://www.intec.co.uk/xots-background-and-multithreaded-tasks-the-openntf-domino-api-way-part-two/的相关博客文章(将“两个”替换为“一”和“三”用于该系列的其他部分)。

XOTS 非常适合并行处理,并允许配置线程数,默认为 10。

当我查看 XPages 中的线程文档时,我发现博客文章提出了该文章未涵盖的潜在问题,但没有详细说明。我没有进一步调查。

于 2015-06-23T10:43:08.633 回答