| 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: 11691
|
|
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
|
Java Resources at www.wbrogden.com
|
 |
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: 11691
|
|
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.
|
 |
 |
|
|
subject: Multi-threading in web services ?
|
|
|