I’ve just started using Java EE recently to build webservices.
Most of these have been very simply in that they get a request, do some work, and return a result. Once the result is returned to the client it dies.
Now I need to be able to respond to the client, to indicate that it’s request has been received and that it is being processed, but I don’t want to end the webservice thread after sending the request. I need it to do some processing after responding like sending requests to other webservices. The client will then routinely poll to get the outcome of the result. This will be handled by another webservice call thread.
I’m not sure if this is possible in Java EE. I’ve generally only done this using xml of TCP sockets.
Starting with Java EE 6, it’s possible to define EJB’s methods as asynchronous: see Asynchronous Method Invocation. So your routine would be calling an asynchronous bean from the bean handling your web service, to trigger the start of your lengthy process, and returning to the client. You can then query the result of this process through a different web service method.
In Java EE 5 it’s also possible, though not directly, but utilizing timer tasks. It is, however, not possible to query the result of such task automatically, so you’d have to design it so that it saves its state in a database, from where another bean could read it.