• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to handle an asynchronized scenario?

 
David Chen
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
David Chen
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic