Robert Young wrote:
> i'm setting off to build a servlet project, and a (well, many) question
> arises: since servlets are instantiated but once by the servlet
> execution engine, the "conventional wisdom" (which i so far by into) is
> to avoid instance variables and keep variables local to methods.
The primary reason for this is thread safety -- there's only one instance
variable, but there's a method variable for each concurrently executing thread.
>
> assuming that one's project can be done in this way,
If you cannot do this, you're going to have big time problems with simultaneous
access to these variables. The fact that JSPs and servlets run in a
multi-threaded environment is probably the most important single factor in
deciding on your application architecture -- it's a very different place than a
single-theaded application.
> have there been
> occurrences of the stack blowing?? i understand that it is a virtual
> stack in the virtual machine, but since method variables are allocated
> on this "stack", i am concerned that an architectural decision taken
> early on could come back to bite one in a tender spot. i've checked the
> java web site, but couldn't come up with any entries regarding stack
> behavior; with servlets or otherwise.
>
Two things to keep in mind:
* It is up to the JVM to decide how memory is really allocated. The ones
I'm familiar with allocate object references on the stack, rather than the
objects themselves -- thus the memory occupancy (on the stack) is
pretty small.
* Most JVMs have command line options that let you tweak the per-thread
stack size if you need to.
>
> thanx,
> robert young
> oms, inc.
>
Craig McClanahan
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html