Pass Session object to new thread

Is it some way for passing Session object from current thread to a new one ? When I invoked remote service via Service.doInvoke(…) from original server context - everything was working fine. But when I run my new thread and try to do it there, I have NullPointerException during invoke execution. I think it is because the Service.getSession() within my new thread is NULL. I tried to take Session object from original thread and passed it into my thread constructor, then used it for invoked the remote service via another method Service.doInvoke(String, Session, IData) but it doesn’t work too, with the same exception. So, now I have no ideas how I can solve this problem, may be somebody knows another way for do that ?

sy konstantin

Konstantin,

Please check these below threads if it helps,

[url=“wmusers.com”]wmusers.com &
[url=“wmusers.com”]wmusers.com

Cheers,

Try this…
Get the session object from the parent thread, and set the following parameters just before calling Service.doInvoke in the child thread:

InvokeState.setCurrentUser(session.getUser());
InvokeState.setCurrentSession(session);

Hi,

Even I am getting the same error. Can you please help me if this got resolved. please let me know how to pass session object and do the rest of the stuff so that i can invoke the service using doInvoke.

IDataCursor pipelineCursor = pipeline.getCursor();
try
{
FPImpServiceN m1=new FPImpServiceN();
Thread t1 =new Thread(m1);
t1.start();

}
catch(Exception e)
{
throw new ServiceException(e);
}
pipelineCursor.destroy();

Code in source:

static class FPImpServiceN implements Runnable
{
public void run()
{
try
{
NSName nsName = NSName.create( “threadsPOC.services:new_javaService” );
IData outputData = Service.doInvoke( nsName, null ); // Getting Null pointer exception here //
}
catch(Exception e)
{
com.wm.util.JournalLogger.log( com.wm.util.JournalLogger.INFO, com.wm.util.JournalLogger.FAC_FLOW_SVC, com.wm.util.JournalLogger.DEBUG, e);
}
}
}