Ronen Portnoy wrote:
>
> i want to implement a servlet that handles both HTTP and
> raw tcp Sockets connections,
>

 Do you really mean 'raw sockets' as in SOCK_RAW, or do
you mean just 'regular old socket'? I suppose it doesn't
matter, since the answer is basically 'don't do that'.

 You could have a servlet launch a thread that serviced
a socket, but having a servlet launch a thread is maybe
not such a good idea, as it's painful to synchronize the
thread's lifecycle with the servlet's lifecycle.[1]

 Think of it this way: servlets are a way to write an
HTTP front-end to a system. If you need to write a
non-HTTP front-end, don't use servlets.

 If you can give details about what you want to do
with the socket, people on the list might be able
to offer some alternatives...


[1] I just flipped through JH's book at the bookstore,
and noticed that he encourages people to launch threads
in the init() method. While sometimes unavoidable, it's
evil and you shouldn't do it. JDK's prior to 1.4 provide
no completely reliable way to shut down a thread, and
even with 1.4 you have to go through hoops. There are
workarounds for various situations, but unless you're
a guru at that sort of thing you should try and avoid
the whole mess. See:

 "Design note: Interrupts" at:

   http://java.sun.com/j2se/1.4/docs/api/java/nio/channels/Channel.html

 and also the links at the bottom of:

   http://www.distributopia.com/servlet_stuff/background_threads.txt

 especially the Doug Lea "Cancellation" essay:

   http://g.oswego.edu/dl/cpj/cancel.html

 but note that the the essay doesn't mention the
new 1.4 features.

 Yes, if you're writing long-running, reliable apps,
it really is that complicated...


--
Christopher St. John [EMAIL PROTECTED]
DistribuTopia http://www.distributopia.com

___________________________________________________________________________
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