• 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 Model

 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Can anyone tell me if it is advisable to use SingleThreadModels in a Servlet? Most of the responses that i get is, it is not. So how will a servlet handle concurrent requests ?

Thanks
Bitz.
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is almost always a bad idea to use the single thread model, so bad in fact that it has been deprecated and scheduled for removal.

The other option is to manage multi-threading as you would in any other application: manage access, protect shared resources, and synchronize when required. Not a great answer, but you just have to 'be aware'
 
Ranch Hand
Posts: 1704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not advisable and the interface was deprecated.
[ March 20, 2006: Message edited by: KJ Reddy ]
 
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am surprised why Sun introduced the SingleThread i/f. I have never found it useful. :roll:
 
Ranch Hand
Posts: 1140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Pradip Bhat:
I have never found it useful. :roll:



I have found the SingleThreadModel (especially the isThreadSafe attribute in JSP) extremely helpful when I was maintaining a production system. The service level agreements were too tight (Priority 1 defects in production should be fixed with in 4 hours from the time it was first reported). Many of the defects raised were related to multiple threads modifying shared resources.
Since it is almost impossible to debug & fix these defects in 4 hours, I make the pages thread safe by making them single threaded. Then take a day or two to fix the defect in the proper way
 
Kj Reddy
Ranch Hand
Posts: 1704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Mani Ram:

Since it is almost impossible to debug & fix these defects in 4 hours, I make the pages thread safe by making them single threaded. Then take a day or two to fix the defect in the proper way



You are smart
 
Pradeep bhatt
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Mani Ram:


I have found the SingleThreadModel (especially the isThreadSafe attribute in JSP) extremely helpful when I was maintaining a production system. The service level agreements were too tight (Priority 1 defects in production should be fixed with in 4 hours from the time it was first reported). Many of the defects raised were related to multiple threads modifying shared resources.
Since it is almost impossible to debug & fix these defects in 4 hours, I make the pages thread safe by making them single threaded. Then take a day or two to fix the defect in the proper way



Well done.
 
author
Posts: 288
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The multi-threading aids efficiency but the servlet code must be coded in a thread safe manner. The shared resources (e.g. instance variables, utility or helper objects etc) should be appropriately synchronized or should only use variables in a read-only manner. Having large chunks of code in synchronized blocks in your service methods can adversely affect performance and makes the code more complex.Shared resources can be synchronized or used in read-only manner or shared values can be stored in a database table.
 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's not advisable to implement SingleThreadModel as performance will be killed. you shouldn't be using instance variables as well or else you will end up with synchronizing blocks, which again will hit performance.

Originally posted by S bitz:
Hi,
Can anyone tell me if it is advisable to use SingleThreadModels in a Servlet? Most of the responses that i get is, it is not. So how will a servlet handle concurrent requests ?

Thanks
Bitz.

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic