• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Threading issues in servlet

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I am writing an application which involves a servlet which processes user request.This servlet might be accessed by more than one user simultaneously.My question is will the servlet engine(i am using JRun) or the webserver (IIS) take care concurrent user request?is there anything i need to do to make sure that my application doesn't crash?is there any precaution i should take?
also can i call the destroy() method at the end of the servlet?
any help would be greatly appreciated.
Subbu
 
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you will not have to worry about the concurrent issue in this case unless you use SingleThreadModel for your servlet.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is the responsibility of the servlet container to assign a separate Thread to each request. It is the responsibility of the programmer to keep in mind that multiple Threads will be executing the same servlet object. Don't use instance variables for user-specific data, etc.
NEVER call destroy() that is what the servlet container does before removing an instance of your servlet.
Bill

------------------
author of:
 
Subbu Aswathanarayan
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi SoonAnn,
what is the singlethreadmodel and where do we use it?please reply asap.
Subbu
 
Subbu Aswathanarayan
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by William Brogden:
It is the responsibility of the servlet container to assign a separate Thread to each request. It is the responsibility of the programmer to keep in mind that multiple Threads will be executing the same servlet object. Don't use instance variables for user-specific data, etc.
NEVER call destroy() that is what the servlet container does before removing an instance of your servlet.
Bill


Hi Bill,
Thanks for the reply.I will be more specific about my problem.My servlet is going to access a database and will read and write to the database.My question is when one servlet thread is writing to the database how can another servlet read from or write to the same database.
please explain how should i handle this situation.
Thanks.
Subbu
 
SoonAnn Lim
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Subu,
I get the point backward. You may use SingleThreadModel interface to avoid concurrency issue. When using SingleThreadModel interface, you do not have synchronization issue because server will guarantee no 2 threads will execute the service method of the servlet. Be awared this approach is not very efficient for large hit web pages.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic