This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 12761
    
    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: 12761
    
    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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Multi-threading in web services ?
 
Similar Threads
Technologies which have a good scope
certificates on tomcat
css background color question
Communication of servlets in different JVM's
Cleared SCDJWS