Nic Ferrier wrote:
>
> Chris rejoined:
> >The problem is that the servlet container is not going to
> >know about your socket, so it (or the admin) might decide to
> >shut down your servlet in the middle of a socket communication.
> >You don't have any control over that.
>
> Yes you do. A ServletContext lifecycle event can take your Socket
> down cleanly.
>

 You can detect the destroy(), but you don't have any
control over when/whether it happens. So the destroy()
may come in the middle of a back-door-socket communication
with a client. That's going to be awkward to handle
properly [1], since even if the thread and socket still
exist, all the webapps's other resources will have gone
away [2]

 If you simply assume it will never happen, then a
server upgrade may break your app. That might be
acceptable, but it's an engineering compromise that
has consequences for the long term maintainability
of the application.

 A cleaner design [3], if you can afford it, is to
break the app into a servlet gateway that manages a
separate socket-provided service. That way the lifecycles
of the two services can be managed independently.


-cks



[1] "Awkward to handle properly" == "Nobody will bother
to handle it properly" Is it legal to block in destroy()
until the socket conversation is over? Presumbably not.

[2] Would a really robust container take away the thread
and socket too? The socket is easy enough, but with stop()
deprecated, I'm not sure the container has a way to
reap the thread without your cooperation.

[3] It really just depends on the exact requirements.
It might be perfectly ok to just close() the socket
during a conversation with a client. It might be ok
to assume the webapp is never, ever reloaded. Etc. But
a conscientious developer has to at least be aware
that the issues need to be considered.

___________________________________________________________________________
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

Reply via email to