• Post Reply Bookmark Topic Watch Topic
  • New Topic

Threads with servlets

 
vinoth khanna
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am trying to make my servlet methods get and post with threading.
What if I use only synchronized on my get method.


public synchronized void doGet(HttpServletRequest request..


or must I achieve threading in other ways or how(want sample code e.g.. Must I overide servlet API's for Weblogic 7.0.)

Actually..I am reading a file from servlet ,if multiple access comes to the servlet simultaneously, it gives Exceptions.How can I stop that.

And a servlet accessed from one machine simultaneously (above 3) gives problem,but different nodes(above 6 users) doesn't. Why is that so and wat is behind that..

How to bring performance in my servlet case.

Suggest whether threading will work out fro my case.

Thanx All,
Vin
 
Jayesh Lalwani
Ranch Hand
Posts: 502
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never ever put synchronized on your doGet and doPost methods. If you do that then your servlet will be able to service only one client at a time. This will result in serious degradation of your application.

Multi-threading is a complex issue and no one can give you a solution that fits all problems. You have to synchronize code that accesses resources/variables. I know this dioesnt solve your problem, but to solve your problem, you need to analyze your code. putting synchronized on your doGet is a very costly(and could be fatal) cop-out

Jayesh
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Duplicates a post over in Servlet land.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!