简体   繁体   English

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

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

I am planning to use single entry point for all 5 minutes xAgents, meaning one XPage launchs all 5 minutes "java agents" (classes that should be launched every 5 minutes). 我计划对所有5分钟的xAgent使用单一入口点,这意味着一个XPage将启动所有5分钟的“ java代理”(应该每5分钟启动的类)。 I would like to lauch that java code in new different Threads to have true parallel lauch of such agents. 我想让新的不同线程中的java代码具有真正的并行此类代理。

The mentioned "java agents" have strong interdependency with other NSF app classes. 提到的“ java代理”与其他NSF应用程序类具有很强的相互依赖性。 Many of them rely on FacesContext and / or other XSP / JSF global variables. 其中许多依赖于FacesContext和/或其他XSP / JSF全局变量。

"Java agent" code example: “ 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();
}
}

The issue: Such methods like: FacesContext.getCurrentInstance(), ExtLibUtil.getCurrentSessionAsSigner() return NULL in new Thread. 问题:诸如FacesContext.getCurrentInstance(),ExtLibUtil.getCurrentSessionAsSigner()之类的方法在新线程中返回NULL。

The question: Is it possible to init XSP / JSF engine inside new Thread to get access to FacesContext, etc (to get not null in lines "Agent1: test 2.1" and "Agent1: test 2.2")? 问题:是否可以在新线程内初始化XSP / JSF引擎以访问FacesContext等(在“ Agent1:测试2.1”和“ Agent1:测试2.2”行中不获取null)?

Thanks in advance! 提前致谢!

I encountered a similar problem when developing with XOTS in OpenNTF Domino API. 在OpenNTF Domino API中使用XOTS进行开发时遇到了类似的问题。 The best option is to pass whatever objects are needed in the constructor. 最好的选择是传递构造函数中所需的任何对象。 Here's the relevant blog post on XOTS http://www.intec.co.uk/xots-background-and-multithreaded-tasks-the-openntf-domino-api-way-part-two/ (replace "two" with "one" and "three" for the other parts of the series). 这是XOTS上的相关博客文章,网址为http://www.intec.co.uk/xots-background-and-multithreaded-tasks-the-openntf-domino-api-way-part-two/ (用“一个”和“三个”(系列的其他部分)。

XOTS works very well for parallel processing and allows configuration of the number of threads, by default 10. XOTS非常适合并行处理,并允许配置线程数,默认情况下为10。

When I looked at documentation for threading in XPages, the blog posts I found suggested potential issues not covered in that post, but didn't elaborate. 当我查看XPages中的线程文档时,我发现该博客文章暗示了潜在的问题,但并未对此进行详细说明。 I've not investigated further. 我没有进一步调查。

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

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