Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multi-threading in web services ?

 
Alex Parvan
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do web services need threads ? And if yes, what do i have to do ?

Thanks,
Alex
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13064
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13064
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think i understand, the operations should not depend one on another, or on the same object.

Thanks, this was helpful.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic