• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

asynchronous communication between java and servlets

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
--------------------------------------------------------------------------------
Hello Friends,
I would like to know if there is any way of achieving asynchronous communication from java to a URL(i.e. servlet).
I have a java method from which I shall post some information to a url(by opening a url connection) and keep going without waiting for response from the url. I would like to know if a POST request is synchronous or asynchronous. If the url takes 10 minutes to process the request(for example :-)), my java code is impatient to wait that long. It just wants to post the data and continue without caring for the response from the url.
(I know that messaging architecture could be used here. However, do not want to go into such complications in the architecture.)
Just tell me what happens if I do the following:
1. I open a url connection from java code.
2. Post data to the url from java code (the url starts processing data...).
3. I close the connection (the url has not finished processing yet).
4. I continue with rest of my java code.
Do you guys think that this would achieve my purpose. Any suggestions?
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

1. I open a url connection from java code.
2. Post data to the url from java code (the url starts processing data...).
3. I close the connection (the url has not finished processing yet).
4. I continue with rest of my java code.


You have not quite thought this out. The data POSTed does not have to be processed in the same Thread that accepts the request. Instead, your servlet should hand the data off to a worker Thread and generate a response indicating that the data was received. Later requests to the servlet can get responses indicating the state of data processing.
Generally speaking, the request / response cycle should be completed as quickly as possible - long running calculations can usually be farmed out to Runnable worker classes. This general topic comes up frequently here and in the JSP forum.
Bill
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic