my dog learned polymorphism*
The moose likes Web Services and the fly likes Multi-threading in web services ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Multi-threading in web services ?" Watch "Multi-threading in web services ?" New topic
Author

Multi-threading in web services ?

Alex Parvan
Ranch Hand

Joined: Dec 10, 2009
Posts: 115
Do web services need threads ? And if yes, what do i have to do ?

Thanks,
Alex


"Quoting yourself is stupid" - Me
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12787
    
    5
You certain need to be aware of the fact that a web service may be handling many request = many threads "at the same time."

If your service is hosted in a HTTP container such as Tomcat, the container will manage the Thread which executes the request. The programmer just needs to use good practice to prevent interference between request.

Bill
Alex Parvan
Ranch Hand

Joined: Dec 10, 2009
Posts: 115
So i don't need threads ? If i have 20+ operations that read from a db and returns values and hundreds of users using them, tomcat will handle everything ?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12787
    
    5
Tomcat will create a separate Thread for each request but it is up to you to control access to shared resources such as a database or any instance variable.

For example, it is always strongly recommended that you use a DB connection pool library - you certainly can't share one single DB connection with multiple simultaneous request.

Bill
Alex Parvan
Ranch Hand

Joined: Dec 10, 2009
Posts: 115
I think i understand, the operations should not depend one on another, or on the same object.

Thanks, this was helpful.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Multi-threading in web services ?