aspose file tools*
The moose likes Servlets and the fly likes LogServlet Sends response first and then processes request Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "LogServlet Sends response first and then processes request" Watch "LogServlet Sends response first and then processes request" New topic
Author

LogServlet Sends response first and then processes request

Haarshal Kul
Greenhorn

Joined: Sep 01, 2011
Posts: 3

I have a servlet that receives the post http request and logs the data in the HTTP body. It does not return anything back and client does not need anything other than HTTP 200 status.

Lately we have seen a lot of delay in this process due to heavy load. Can I just commit the response using either flushBuffer() or PrintWriter flush() and close()?

Are there any disadvantages to that?

Logging process can it's sweet time once the response is sent. Am I thinking right?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60080
    
  65

Nope. If you want the long process to happen independent of the response, you'll need to fire it off in its own thread.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Haarshal Kul
Greenhorn

Joined: Sep 01, 2011
Posts: 3

Ok that makes sense. I can spawn threads for these.
Haarshal Kul
Greenhorn

Joined: Sep 01, 2011
Posts: 3

Thanks a lot.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: LogServlet Sends response first and then processes request
 
Similar Threads
an unnatural act
Sending a http-request without waiting for response
Set Managed Bean property (value) without user interaction
Faces Context null in serveResource Request
How to use Threads in Servlets?