aspose file tools*
The moose likes Servlets and the fly likes How to handle an asynchronized scenario? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to handle an asynchronized scenario?" Watch "How to handle an asynchronized scenario?" New topic
Author

How to handle an asynchronized scenario?

David Chen
Ranch Hand

Joined: Jan 06, 2002
Posts: 57
Hi, there:

I had an asynchronized scenario in my web application. After client side collecting information and click "submit", my servlet in server side is supposed to wrap those information in a transaction and send it to 3rd party engine, however, the response of that transaction from the 3rd party engine is asynchronized (may take several minutes).
Question:
At client side, after user click "submit", what should I do?
a. tell user transaction is submitted successfully, and ask him to check response later;
b. display some information like "please wait, your transaction is processing ..........", and my servlet keeps polling response, and send html response back after get response from 3rd party?
c. Or, servlet send response back immediately, however, somehow to get client side keeps sending request to servlet to check the status of transaction?

Highly appreciated if any suggestion or comments.

Thanks a lot in advance

David
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61433
    
  67

Whenever I've had a similar scenario, I've used option "a". It's tidy, clean, and allows the user to get about doing whatever they want while the long process happens in the background.

This, of course, assumes that you have a way of checking for the status (could be a simple as complete/not-complete) of the aynch operation.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
David Chen
Ranch Hand

Joined: Jan 06, 2002
Posts: 57
Thank you very much, Bear, for quick reply. Just want to know if anyone did try some other approach.

Thanks a lot
David
David Chen
Ranch Hand

Joined: Jan 06, 2002
Posts: 57
However, there are quite a lot of online shopping sites, after you input your credit card number, amount etc. and submit. You are waiting for card authorization back. How do they handle those scenarios? like during waiting for response, the client back or forward or navigate to other links, pages, or even shut down the browser? Also, for those time consuming tasks in serverside, if hundreds of requests come at almost the same time, and it takes servlet quite long time to wait for each response, will it cause any problem in server side? like performance, resource issue?

Highly appreciated if any suggestion or comments on it.

Thanks a lot
David
David Chen
Ranch Hand

Joined: Jan 06, 2002
Posts: 57
By the way, because it may take quite long time (about 1 or 2 minutes) in my servlet to get response from 3rd party, which, may cause some performance, resources issues in my server side if hundreds of requests come simultaneously.
So, some one suggests me start a new thread in my servlet in server side for each client request.
My question: will spawn a new thread in servlet help? Isn't that web server's responsibility to generate a new servlet entity to serve the new request? Even I spawn a new thread to wait for response, the original servlet in sleep mode, does it help to improve performance in server side?

Highly appreciated any comments or suggestions, thanks a lot in advance

David
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to handle an asynchronized scenario?