在xAgent中访问FacesContext(在新线程中)

时间:2015-06-23 10:28:59

标签: java jsf xpages facescontext

我打算在所有5分钟的xAgent中使用单一入口点,这意味着一个XPage将启动所有5分钟的“java agent”(应该每5分钟启动一次的类)。我想 lauch认为新的不同主题中的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" )?

提前致谢!

1 个答案:

答案 0 :(得分: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。

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