aspose file tools*
The moose likes Servlets and the fly likes long running service call and tracking completion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "long running service call and tracking completion" Watch "long running service call and tracking completion" New topic
Author

long running service call and tracking completion

manish ahuja
Ranch Hand

Joined: Oct 23, 2003
Posts: 312
Hi All,

I have a servlet which talks to a web service. The web service method is representation wrapper for a batch program which could take somewhere between few hours or a day max to finish.
I had this create as an asynchronous web service call. At the end this web service updates a backend table with the status as 'COMPLETED'

But now I have to call another web service after completion of the first web service.
My question is what is the best way to keep track of the completion of a long running service in my case the first web service completion.

Should i change the asynchronous web service to synchronous mode which would mean keeping a thread open for a day or should i opt for some sort of polling service which checks for an event.

Let me know your thoughts on this.

Regards,
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
How to do it depends on what you have running and where you want to start this second web service call. Some possibilities:

1. eMail
2. JMS - Java messaging service
3. Manage the initial request and subsequent request through a JavaSpaces server

Bill

manish ahuja
Ranch Hand

Joined: Oct 23, 2003
Posts: 312
Thanks Bill.
Ideally we would want to manage the second web service call in seamless fashion. But the second web service cannot start till the first web service completes its task.

I am not conversant with Javaspaces. But with JMS i believe you mean the first web service drops a message on the Queue when it completes and the subscriber of the Queue kicks off the second web service based on the receipt of the completion message.

Can we spawn a separate runnable thread to initiate the first web service call and make the servlet spawning it wait.
After completion of this thread the servlet will trigger the second web service call.

Let me know your thoughts on the threading solution.


Regards,



William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
Can we spawn a separate runnable thread to initiate the first web service call and make the servlet spawning it wait.
After completion of this thread the servlet will trigger the second web service call.


No no no, you should never make a servlet request thread wait. Too many ways for things to go wrong - there should be an initial response which tells the client that the process has been started.

Instead have a web service call manager class to subscribe to the JMS and manage the whole process in a separate Thread.
Make this class independent of the servlet environment so you can test and debug. Handling all the possible errors needs to be carefully thought out.

Bill
manish ahuja
Ranch Hand

Joined: Oct 23, 2003
Posts: 312
Thanks Again Bill.

Instead have a web service call manager class to subscribe to the JMS and manage the whole process in a separate Thread.


Can you confirm this understanding. Considering we have two long running web services to be run sequentially, the Web Service 1 after completion will drop a message on JMS queue and the subscriber (manager class) to this queue will trigger web service2
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
Sounds good to me.

Make sure you provide for recording/recovery from errors and don't leave any connections open.

Repeating myself but this is important, design so that you can test the manager outside the servlet environment. A bit of extra work but you will be glad you did.

Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: long running service call and tracking completion