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

Posts: 115

posted 8 years ago

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 ?

"Quoting yourself is stupid" - Me

William Brogden

Author and all-around good cowpoke
Rancher

Posts: 13078

6

posted 8 years ago

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

Posts: 115

posted 8 years ago

I think i understand, the operations should not depend one on another, or on the same object.

Thanks, this was helpful.

"Quoting yourself is stupid" - Me

PI day is 3.14 (march 14th) and is also einstein's birthday. And this is merely a tiny ad: