• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

abnormal behaviour

 
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wrote this jsp:
and tested it under tomcat 5.0
<%@page buffer='512kb' isThreadSafe='false'%>
<%!static int qtdInstances=0;%>
<%!static int qtdMortos=0;%>
<%{qtdInstances++;}%>
<br>
quantidade de Instancias:<%=qtdInstances%>
<br>
quantidade de mortos:<%=qtdMortos%>
<%!
public void finalize(){
qtdMortos++;
}
%>
Notice that the number of instances is only increasing, and the number of garbage-collected objects is never decresing, is it normal?? shouldn't tomcat have the instances in a pool?
 
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It probably does have the instances in a pool, but that doesn't mean that it destroys the instances after each use. The whole point of pooling is to increase performance on servlets that implement SingleThreadModel so that you can use whatever instance is available when multiple requests arrive. Of course you also know that you may be waiting forever for any instance to be GCed and finalized anyway.
 
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi leandro,
One more thing to remember, the specification does not assure that the finalize() method will always be invoked.
Unlike standalone java applications, we cannot relay on the finalize() method to release the resources in Web and Enterprise applications.
Nick.
 
Leandro Oliveira
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
guys, I've requested this page many times, and what I could notice was that for each request, tomcat 5.0 created a new instance of this page. Last night I did 4600 requests to this resource and 4600 objects were created, my memory usage increased linearly... I'm afraid of using singleThreadModel in a highly visited aplication, since we may have OutOfMemoryError...
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm afraid of using singleThreadModel in a highly visited aplication
And I think that is the whole point. For industrial strength web apps, you should probably never use SingleThreadModel, but design your app so that they are inherently thread safe, no instance or static variables, no mutable context attributes (or synchronize them), etc. From what you say, it would appear that Tomcat 5 doesn't pool at all, but just creates a new instance on each request, that seems wasteful, but would be easier to implement than pooling.
 
Author
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by leandro oliveira:
guys, I've requested this page many times, and what I could notice was that for each request, tomcat 5.0 created a new instance of this page. Last night I did 4600 requests to this resource and 4600 objects were created, my memory usage increased linearly... I'm afraid of using singleThreadModel in a highly visited aplication, since we may have OutOfMemoryError...


Originally posted by leandro oliveira:
guys, I've requested this page many times, and what I could notice was that for each request, tomcat 5.0 created a new instance of this page. Last night I did 4600 requests to this resource and 4600 objects were created, my memory usage increased linearly... I'm afraid of using singleThreadModel in a highly visited aplication, since we may have OutOfMemoryError...


Hi,
I think you wanted to use this construct
<%!{qtdInstances++;}%>
Note the ! in <%! to make it an instance initializer. Without !, it is just a scriplet (part of the _jspService method) that will be executed for each request, hence the high value printed by <%=qtdInstances%>
Also, as Michael suggested, you probably don't want to use isThreadSafe or SingleThreadModel at all. That interface is depricated in the new version of the specs.
 
Leandro Oliveira
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you're right!!
Tomcat is pooling the objtects!!
It was a matter of coding!
Sorry for this mistake guys...
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic