File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Performance and the fly likes performance using SingleThreadModel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Performance
Bookmark "performance using SingleThreadModel" Watch "performance using SingleThreadModel" New topic
Author

performance using SingleThreadModel

Leandro Oliveira
Ranch Hand

Joined: Nov 07, 2002
Posts: 298
Guys,
I have any of you used SingleThreadModel in this situation:
Suppose you have a servlet, or jsp document that creates many objects, initialises this objects, pass some parameters to these objects, than they do that processing returning some result needed to the page, in other words, this page uses lots of jsp actions (taglibs) and page scoped beans.
What do you think about notifing this page as SingleThreadModel (in servlets by implementing SingleThreadModel, in jsp pages by stating that the page isThreadSafe='false')? doing this, almost all containers will create instances of this page or servlet and pool them to the incoming requests. if we make these page scoped beans instance variables and make all initialization within jspInit() or init() methods do you think that this page creationg and pooling can make this page less havier than executing its service method, allocating memory for the beans, initializing these beans???
Thanks!
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12778
    
    5
I believe I have followed your argument and the answer is no - there is no good reason to use SingleThreadModel. You could end up creating the same number of page scoped beans as with the normal model and miss many chances to create objects that can be shared by all requests. Furthermore, object creation is not that big a perfomance hit in most cases - if you need objects that are expensive to create, use an object pool.
The SingleThreadModel is a leftover from the early days of servlets when people were still trying to make the mental jump from desktop-single user applications to the sevlet request-response/shared code model.
Bill
[ March 02, 2004: Message edited by: William Brogden ]
Leandro Oliveira
Ranch Hand

Joined: Nov 07, 2002
Posts: 298
suppose the objects are already created, and implementing object pooling will require more time than you have...
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12778
    
    5
Are these objects actually that expensive to create or are you just guessing? Do you have a complete example running so that you could actually measure some times?
I think there are plenty of examples of object pooling floating around that you could adapt.
Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: performance using SingleThreadModel