File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Tomcat and the fly likes Controlling sequence of processing individual requests Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Controlling sequence of processing individual requests" Watch "Controlling sequence of processing individual requests" New topic
Author

Controlling sequence of processing individual requests

Dave Klein
author
Ranch Hand

Joined: Aug 29, 2007
Posts: 77
Is there any way to control the order of processing of individual requests in Tomcat? Say that 100 requests come in within a 1 second period and the handling of each request takes 3 to 4 seconds. Is there any way to ensure that each of those requests is completed in the order it is received?

Thanks,
Dave


Author of Grails: A Quick-Start Guide
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61092
    
  66

No.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Dave Klein
author
Ranch Hand

Joined: Aug 29, 2007
Posts: 77
That's what I thought, but I'm being asked to do just that. Can you point me toward any references or articles that would explain this fact? My saying "It doesn't work that way" isn't cutting it.

Thanks,
Dave
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61092
    
  66

There is no configuration that controls how the order of unrelated requests are handled. I'm not sure how else to word it.
Himanshu Kansal
Ranch Hand

Joined: Jul 05, 2009
Posts: 257
I might not be wrong if I say that requests are threaded and thread behaviour is unpredictable. Maintaining such an order is synonymous to running them serially which is not the concept.


Experience and talent are independent of age
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
Seems to me you could write your own mechanism - how about putting each arriving request Thread in a queue in a long sleep state. A separate working Thread could remove a request Thread from the queue and interrupt it to resume processing.

Bill
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61092
    
  66

I'd fear disastrous effects on performance, but if the requirement is more important than reality...

Can you find out the reason of this rather bizarre requirement? It smacks of a sledge-hammer approach to solve another problem that probably has a simpler and less weird solution.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16019
    
  20

HTTP servers are designed to handle all requests at an equal priority. In theory, that means first-in, first-out, but in the case of HTTP servers like Tomcat and Apache, the requests are dispatched to individual handler threads running asynchronously, so the concept of order of arrival doesn't even begin to apply until all the threads in the server are busy and queueing needs to be done.

This isn't just a Tomcat issue, and it isn't just a Java issue. Like the forbidding of unsolicited responses, it's part of the basic architectural definition of how HTTP works as defined in the various RFCs that make up the standards.

If you want some sort of ordering or prioritizing, you'd have to look elsewhere. To make a FIFO out of an HTTP server, you'd actually have to downgrade its functionality (use only one thread). If you're looking at prioritization of traffic, you'd generally have to play games with your routers and switches.

Alternatively, you could use a non-HTTP protocol that supports such refinements, such as a messaging service. However, non-HTTP means that you'll need a custom app to submit them, since web browsers deal in HTTP, and like I said, HTTP doesn't support that.


Customer surveys are for companies who didn't pay proper attention to begin with.
Dave Klein
author
Ranch Hand

Joined: Aug 29, 2007
Posts: 77
Thanks all, your comments have been very helpful.

Dave
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Controlling sequence of processing individual requests