Hi fml2,
Thanks for the reply. Those methods are present in
import com.wm.app.b2b.server.Session;
import com.wm.app.b2b.server.StateManager;
Regarding the approach i am using for killing the thread please go through the following code.
Main code:
IDataCursor pipelineCursor = pipeline.getCursor();
try
{
long timeout = 10000;
String serviceName = “threadsPOC.services:new_javaService”;
int i=0, startTimer=0;
FilePullImpService m1=new FilePullImpService(serviceName);
Thread t1 =new Thread(m1);
while(true)
{
if(i==0)
{
i++;
t1.start(); /* Invoking the thread class*/
com.wm.util.JournalLogger.log( com.wm.util.JournalLogger.INFO, com.wm.util.JournalLogger.FAC_FLOW_SVC, com.wm.util.JournalLogger.DEBUG, "Thread Class Started");
}
else if(startTimer < timeout)
{
IData status = m1.returnval(); /*check If Thread completed execution. If completed then status will not be null*/
if(status != null)
{
IDataUtil.put( pipelineCursor, "output", status );
break;
}
else
{
startTimer +=1000;
t1.join(1000); /* wait for 1000 milli seconds for thread to get completed */
System.out.println(startTimer);
}
}
else /*If timeout exceeded and thread failed to complete */
{
System.out.println("Thread Faied To Complete Before Timeout");
System.out.println("Status Of Thread Before Killing " + t1.getState());
t1.stop(); /* Stop the thread */
System.out.println("Status Of Thread After Killing " + t1.getState());
IDataUtil.put( pipelineCursor, "output", null );
break;
}
}
}
catch(Exception e)
{
throw new ServiceException(e);
}
pipelineCursor.destroy();
Code in Source Area:
static class FilePullImpService extends Thread
{
String serviceName;
IData outputData = null;
Session s = null;
FilePullImpService(String serviceName)
{
this.serviceName = serviceName;
}
public void run()
{
com.wm.util.JournalLogger.log( com.wm.util.JournalLogger.INFO, com.wm.util.JournalLogger.FAC_FLOW_SVC, com.wm.util.JournalLogger.DEBUG, "Inside Thread Class");
try
{
com.wm.app.b2b.server.User user = com.wm.app.b2b.server.UserManager.getUser("Administrator");
Session s = StateManager.createContext(0x7fffffffL, "System", user);
s.setUser(user);
s.clearModified();
NSName nsName = NSName.create(serviceName); /* Invokes The flow/Java service for execution */
outputData = s.invoke(user, nsName, null );
StateManager.deleteContext(s.getSessionID());
}
catch(ThreadDeath e)
{
com.wm.util.JournalLogger.log( com.wm.util.JournalLogger.INFO, com.wm.util.JournalLogger.FAC_FLOW_SVC, com.wm.util.JournalLogger.DEBUG, "Caught Thread Death Exception");
}
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, "Exception Caught In Thread Class");
}
}
public IData returnval()
{
return outputData;
}
}
After Killing The thread i can able to see the server log “Caught Thread Death Exception”. But still the service which invoked through thread class continues to run in the background. I want to stop its execution when the thread got killed using t1.stop(). Please let me know if any suggestions or help for achieving this ?
Thanks,
vinodkumar