• 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

single thread or multi thread ?

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have been asked this question in an interview. With respect to servlets when do I go for multithreaded programming or single threaded.
Sim Sim
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Basically servlets are multithreaded by design. Meaning single object instance of servlet will serve all the clients. In a specific scenario, when you expect concurrency will affect the integrity of data, you can go for single threaded servlet by implementing Single Thread Model interface.
Hope this answers your question.
Cheers
Murthy
 
Ranch Hand
Posts: 282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is this correct? Single Thread Model has the impact on performance.
 
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, single thread model criples performance as the servlet has to complete servicing a request before servicing another one (it can't service more than one request at a time).
However, this does not mean that only one servlet will be loaded. The most common behavior is for the servlet container to instantiate more than one instance of the servlet each for servicing a particular request. This kills performance as every instance has to be initialized and then destroyed for every request without counting the effect of many instances loaded in memory. If you have thousands of such instances, your server will take a hit.
Synchronization will still be an issue if those instances have to access common external (external to the servlet) resources.
[ February 05, 2004: Message edited by: Brahim Bakayoko ]
 
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Single Thread Model degrade the servlet performance dramatically, it is just
a reference Model for Multithreaded Model.
In reality, it is not much of use.
Pay attention to the following synchronization issues when you write a multithreaded servlet service:
a. access servlet instance variables
b. access session shared data
c. access application shared data
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic