繁体   English   中英

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

[英]Access FacesContext in xAgent (in new Thread)

我计划对所有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:测试2.1”和“ Agent1:测试2.2”行中不获取null)?

提前致谢!

在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中的线程文档时,我发现该博客文章暗示了潜在的问题,但并未对此进行详细说明。 我没有进一步调查。

暂无
暂无

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

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