0

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). I would like to lauch that java code in new different Threads to have true parallel lauch of such agents.

The mentioned "java agents" have strong interdependency with other NSF app classes. Many of them rely on FacesContext and / or other XSP / JSF global variables.

"Java agent" code example:

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.

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")?

Thanks in advance!

AndrewG10i
  • 661
  • 1
  • 6
  • 21
  • What exactly do you need from the `FacesContext` outside the HTTP request thread running through the `FacesServlet`? Just pass *that* information instead during thread's construction. – BalusC Jun 23 '15 at 10:33
  • @BalusC, thank you for advice, in this particular case I need to get access to specific environment variables of IBM Domino XPages, like ExtLibUtil.getCurrentSessionAsSigner() etc. I will investigate this was also... – AndrewG10i Jun 23 '15 at 10:51
  • ...yep, already found this post: [FacesContext and “Servlet” Context](http://stackoverflow.com/questions/3754327/facescontext-and-servlet-context), will investigate how it can help in my case... – AndrewG10i Jun 23 '15 at 10:59
  • Rule of thumb - never mix notes objects across threads. With HTTP (XPages) you get deadly combination. – Frantisek Kossuth Jun 23 '15 at 13:47
  • @FrantisekKossuth thanks, yes, I keeps that in mind... But this is a little bit different case, especially as main thread will wait for all secondry threads to end. Any ideas re my initial post? Is it possible to get SessionAsSigner inside new thread? Thanks! – AndrewG10i Jun 23 '15 at 13:56
  • inspiration: http://xpagesera.blogspot.sk/2012/03/multi-threaded-programming-in-xpages.html – Frantisek Kossuth Jun 23 '15 at 14:03
  • @FrantisekKossuth, yep, good example, but I had troubles making it work properly on Domino 9.0.1 FP3 (java policy all permission applied)... Anyway it doesn't fully help in my case (I think so). Currently, the most doable scenario - is to pass necessary objects via constructor... – AndrewG10i Jun 23 '15 at 14:11

1 Answers1

0

I encountered a similar problem when developing with XOTS in OpenNTF Domino API. 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 works very well for parallel processing and allows configuration of the number of threads, by default 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. I've not investigated further.

Paul Stephen Withers
  • 15,699
  • 1
  • 15
  • 33
  • Thanks Paul, this is also my consideration to go in such way. Working few last days on this topic I have already read a lot of xAgents / Thread in XPages posts, including all your series of posts re XOTS. ) Re "When I looked at documentation for threading in XPages" can you please share sources or name of that documentation? Thank you! – AndrewG10i Jun 23 '15 at 10:56
  • I think it was the XPages Insights in Big Data project and video http://www.openntf.org/internal/home.nsf/project.xsp?action=openDocument&name=XPages%20Insights%20into%20Big%20Data – Paul Stephen Withers Jun 23 '15 at 11:19
  • Aha, okay, thanks! ...will review the video to refresh it in my memory. – AndrewG10i Jun 23 '15 at 12:09