said:
>>But the OP was talking about Filters not Servlets (even though he
>>calls them Filter Servlets)
>Yes, I am talking about filters and i guess they are also servlets.
>If the filter doesnt implement singlethreadmodel , then what will
>happen?
>Will multiple requests go through different copies of filter object?
>What does actually happen? Some explanation with physical
>interpretation (like if multiple copies of filter object are made in
>memory ) would be helpful.
Ouch; didn't check the specs last time to check whether filters
are anyhow related to servlets, and actually I am too tired to do it
now, either.
Here's how it goes with servlets -- I don't know whether the
SingleThreadModel has any effect on filters.
- if the servlet does not implement SingleThreadModel, the servlet
engine most possibly creates just one copy of the servlet object
(the object will be created at latest at the point where it is
called for the first time during the lifetime of the application
instance; the engine is also free to let any servlet instance be
garbage collected whenever there are no active requests being
processed within the servnet instance)
- corollary: multiple threads of control may be simultaneously
executing within a single servlet instance - thus, servlets
must be coded to be thread-safe
- if the servlet does implement SingleThreadModel, then the servlet
engine will make sure that just one thread of control at a time is
executing within the service methods of the servlet -- however, the
engine is completely free to create multiple instances of the
servlet to provide for multiple simultaneous requests for the
same servlet; as above, the servlet engine is also free to let
the servlet instances be garbage collected
- here the container handles the thread-safety, to some extent at
least; I think there are some accesses (f.ex. to application
context objects) where thread-safety must be explicitly coded for
.... and writing this made me realize an interesting issue with the
destroy() method of servlet. It's commonly known that one cannot
trust that the destroy() is ever called. Now I also am aware that
when the destroy() is called, other instances of the same servlet
class may still be active. While this shouldn't be a concern in
most situations, I think this was a worthwhile discovery..
--
Wolf a.k.a. Juha Laiho Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)