• Post Reply Bookmark Topic Watch Topic
  • New Topic

Single Thread Model  RSS feed

 
S bitz
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • 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.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • 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'
 
Kj Reddy
Ranch Hand
Posts: 1704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not advisable and the interface was deprecated.
[ March 20, 2006: Message edited by: KJ Reddy ]
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am surprised why Sun introduced the SingleThread i/f. I have never found it useful. :roll:
 
Mani Ram
Ranch Hand
Posts: 1140
  • Mark post as helpful
  • send pies
  • 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
  • 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: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • 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.
 
ak pillai
author
Ranch Hand
Posts: 288
  • Mark post as helpful
  • send pies
  • 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.
 
Vicky Pandya
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!