File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Will you ever really need to spawn separate thread if you are writing servlets? 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 » Java » Servlets
Bookmark "Will you ever really need to spawn separate thread if you are writing servlets?" Watch "Will you ever really need to spawn separate thread if you are writing servlets?" New topic
Author

Will you ever really need to spawn separate thread if you are writing servlets?

Ipsita Naravane
Greenhorn

Joined: Dec 27, 2000
Posts: 29
Here's the thing. Let's say I have a servlet that aacepts some query from the user and runs it against the database, and if I wanted to allow multiple queries to run simultaneously, I don't need to explicitly spawn a new thread right? When a request is sent to the app server, it will automatically spawn a new thread correct? So all I need to be sure of is that the data consistency issues etc. and synchronization is properly handled in my code. Am I correct in assuming this?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
1. Each request gets its own Thread - typically a pool of Threads is managed by the servlet container.
2. Servlets must be designed around the request/response cycle. Client applications - typically browsers with humans looking at them - have an expectation that they will get a response within a certain amount of time.
3. IF your queries can execute within the expected time you don't need to do anything special. The request Thread can handle it.
4. IF your request sets off a process that will take a long time (relative to what the client expects) you WILL have to do something special that may or may not involve spawning a new Thread that works while the original request Thread sends some reassuring message back to the user.
5. This sort of thing gets discussed a LOT around here so browse around in the historical forum threads.
Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Will you ever really need to spawn separate thread if you are writing servlets?