users@glassfish.java.net

Re: Interrupting a running Servlet

From: <glassfish_at_javadesktop.org>
Date: Thu, 03 Apr 2008 12:26:38 PST

Thomas, a possible solution would be to use a seperate thread to actually start the native method. In the run()-method you could call the native code which according to my understanding lasts for quite a while. Of course the thread would have to have a reference to an object in the ServletContext (if you want to use the application scope) to which you can pass the result. The concrete implementation of CServerService seems to be a possible candidate for that. Now your implementation of whartung's interface would start the thread in the startService() method.

I think all other methods (check whether a result has already been set, return the result, stop the process) do not have the need for a seperate thread since they all return quickly.

From within your servlets you'd just call the necessary method of the CServerService which then starts a seperate thread if needed. All servlets return immediately. So you must poll for state changes and the actual result.

Thus your servlet indrectly starts the new thread. On behalf of your client, but the client only issues http requests to your servlet.
[Message sent by forum member 'writtmeyer' (writtmeyer)]

http://forums.java.net/jive/thread.jspa?messageID=267632