【发布时间】:2015-06-23 10:28:58
【问题描述】:
我计划对所有 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")?
提前致谢!
【问题讨论】:
-
在运行通过
FacesServlet的HTTP 请求线程之外的FacesContext究竟需要什么?只需在线程构建期间传递 那个 信息。 -
@BalusC,感谢您的建议,在这种特殊情况下,我需要访问 IBM Domino XPages 的特定环境变量,例如 ExtLibUtil.getCurrentSessionAsSigner() 等。我会调查这也是.. .
-
...是的,已经找到这篇文章:FacesContext and “Servlet” Context,将调查它对我的情况有何帮助...
-
经验法则 - 切勿跨线程混合笔记对象。使用 HTTP (XPages),您可以获得致命的组合。
-
@FrantisekKossuth 谢谢,是的,我牢记这一点......但这有点不同,特别是因为主线程将等待所有辅助线程结束。我最初的帖子有什么想法吗?是否可以在新线程中获取 SessionAsSigner?谢谢!
标签: java jsf xpages facescontext