Hello Rahul, from several emails about this topic, I have several suggestions :-)
* the original way you used is a "Asynch way", so after the Utility-Thread is strated, service(...) is finished and the request object is outside the scope. * the new way you used is a "half-synch way", because you still started Utility-Thread to read the stream(this stream is not read in that Thread which runs service(...) and made by Servlet-container and blocked by you), so I think it is a "half-synch way" :-) * from Servlet spec2.3, I remember if container wants to destroy a instance-of- MyServlet(which is for a Servlet-defination), the container will wait there until all the service-Threads "from" this instance are "ended", then call destroy(), then make that instance GCed. so if you can make sure that your service(...) will be blocked there until all your Utility-Threads(and all objects used by these Utility-Threads) are "ended" and "GC-ready", perhaps you can try. But perhaps you need to consider other issues: - does the socket/service in a Servlet-container have a TimeOut-limit? how long can you keep your service(...) blocked there? - do you use HttpSession of other? do they have TimeOut-limit? - how long is your "everage-blocking-time"? what is the max cocurrent service-Threads number which can be provided by container? what is the max cocurrent clients number you will have? and I guess perhaps it is not very good to keep service(...) blocked there for very long time. Happy new year! :-) Bo Dec.31, 2001 ----- Original Message ----- From: "Rahul Asanikar" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Monday, December 31, 2001 7:30 AM Subject: Re: Applet:Servlet using streams in a thread > Yes, I tried it. > If I don't let the service method to return it works. I just don't want the > streams to go out of scope. > Most of the examples of applet servlet communication need to create the > URLConnection object everytime I send a object. If I don't let the service > method return (of course on certain conditions & not always), I can send as > many objects as I can with jus one connection. > I hope this should work!!! > Any comments?? > Best Regards, > Rahul > > > ----- Original Message ----- > From: Christopher K. St. John <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > Sent: Monday, December 31, 2001 1:48 PM > Subject: Re: Applet:Servlet using streams in a thread > > > > > Rahul Asanikar wrote: > > > > > > > > public void service(ServletRequest req,ServletResponse res) > > > { > > > ... > > > ois=new ObjectInputStream(req.getInputStream()); ... > > > r = new receiver(ois); ... > > > rt.start(); ... > > > } > > > > > > Is there anything which prevents the streams to be > > > used in a separate thread? > > > > > > > The stream is no longer valid once the service() method > > finishes. From the 2.3 spec[1]: > > > > SRV.4.10 Lifetime of the Request Object > > > > Each request object is valid only within the scope of > > a servlet s service method, ... Containers commonly > > recycle request objects in order to avoid the performance > > overhead of request object creation. The developer must > > be aware that maintaining references to request objects > > outside the scope described above may lead to non- > > deterministic behavior. > > > > Although it's from the 2.3 spec, it's not a new thing, > > it's a clarification of how it's always been. > > > > So: don't do that. The fact that the request isn't valid > > outside the service method should get you thinking about > > how little else you're really sure is valid outside the > > service method. If a thread references a servlet, and > > the servlet has been unloaded by the container, does it > > make a sound? > > > > > > [1] Blah Blah Spec is available at: > > > > http://java.sun.com/products/servlet/download.html > > > > Download the spec. Read the spec. Obey the spec. All > > hail the spec. Really, honestly, I swear, it's very > > easy to read and just about the bestest friend a > > developer could ever want. > > > > > > -- > > 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