> -----Original Message----- > From: Craig McClanahan [mailto:[EMAIL PROTECTED] > Sent: Monday, December 06, 2004 1:24 PM > To: Struts Users Mailing List > Subject: Re: [OT]Threads and Servlets Question > > > If you're running on a J2EE app server, or a servlet container > configured with appropriate security policies, you won't be allowed to > start a new thread. > > As to why it might be a bad idea, servlet containers make the > assumption that the request and response objects they hand to your > servlet will only be accessed on a single thread, because the servlet > spec includes that requirements. Way too many developers who are > novices at threads try things like accessing the request object from > both the "real" thread provided by the container, and from a second > thread that they have started separately. Or, they expect that they > can save a reference to a particular request beyond the lifetime of > the current request, not aware that the container might be recycling > those objects for some future request. Doing this sort of thing leads > to undefined and inconsistent behavior that is extremely difficult to > debug. > > Finally, way too many developers forget that a thread started by an > application is only known to that application (not to the container) > so it is your responsibiity to shut it down when the app is > undeployed, or when the server is shut down.
That's what I remember now that you mention it... My predecessors decided it would be a good idea to spin a thread to do a webservice call (you're right, bad idea, should have used JMS or other mechanism). They aren't accessing anything from request or response or any other servlet related item. What's happening is that they are getting information from the request... putting it into a bean and giving the bean to the thread to create the XML for the web service call. Problem is, at some point we're losing the data and the bean fields are null. Essentially: TransferBean xferBean = new TransferBean(); xferBean.setDoh( someForm.getDoh()); xferBean.set...(dto.get...); ReallyAnnoyingThreadCall thread = new ReallyAnnoyingThreadCall(xferBean); thread.start(); And at some point as the thread runs.... it's xferBean's fields get set to null. What you're saying is that the request objects from the form are being nulled out by the container? Even though I'm not accessing request directly from the thread? > > Craig > > > On Mon, 6 Dec 2004 11:48:15 -0700, Jim Barrows > <[EMAIL PROTECTED]> wrote: > > Okay... I know I've read this somewhere, but can't remember. > > Why is it recommended you NOT start a thread inside a > servlet, which would translate to "Why is it a bad idea to > start a thread inside an action?". > > And, can you point me at some documentation? > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]