You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jim Barrows <jb...@sssc.com> on 2004/12/06 19:48:15 UTC
[OT]Threads and Servlets Question
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: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [OT]Threads and Servlets Question
Posted by bryan <ni...@gmail.com>.
Object creation with modern JVM's is not that big a problem.
--b
On Mon, 6 Dec 2004 15:18:12 -0500, dgraham@evergreeninvestments.com
<dg...@evergreeninvestments.com> wrote:
> I don't understand your response. Memory (physical and virtual) are also
> finite resources. Does this mean that instantiating new objects is a Bad
> Thing within an action?
>
> Dennis
>
> bryan <ni...@gmail.com>
> 12/06/2004 03:14 PM
> Please respond to
> "Struts Users Mailing List" <us...@struts.apache.org>
>
> To
> Struts Users Mailing List <us...@struts.apache.org>
> cc
>
> Subject
> Re: [OT]Threads and Servlets Question
>
>
>
>
> threads are also a finite resource ( particularly on Linux ).
>
> --b
>
> On Mon, 6 Dec 2004 21:13:57 +0100, bryan <ni...@gmail.com> wrote:
> > because you should use a message driven bean to do something like that.
> >
> > --b
> >
> >
> >
> >
> > On Mon, 6 Dec 2004 11:48:15 -0700, Jim Barrows <jb...@sssc.com>
> 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: user-unsubscribe@struts.apache.org
> > > For additional commands, e-mail: user-help@struts.apache.org
> > >
> > >
> >
> >
> > --
> > http://www.revoltingdigits.com
> > https://jestate.dev.java.net
> >
>
> --
> http://www.revoltingdigits.com
> https://jestate.dev.java.net
>
> ---------------------------------------------------------------------
>
>
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
--
http://www.revoltingdigits.com
https://jestate.dev.java.net
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [OT]Threads and Servlets Question
Posted by Jan Fetyko <li...@fetyko.com>.
Makes sense,
will have to look into JMS I guess, cron is the easiest and it work for 90% of the stuff, oh, well, it rocks.
P.S. In the mean time, this thread about threads, is spinning up new threads, but that's OK, we are all thread safe.
Jf
On Mon, 06 Dec 2004 14:43:55 -0600
Vic <vi...@friendvu.com> wrote:
>A common solution I use is to have async processes run by cron or
>similar to prepare and massage data. A sperate application that runs
>every few minutes and dies.
>
>A long time ago it was said "Batch is bread and butter of IT. View is
>only the icing on the cake."
>
>.V
>
>
>Jan Fetyko wrote:
>> This is interesting,
>>
>> let me ask another related question :
>>
>> What about a thread (started from the Action) that just resizes an image and saves it to a file system ? Would that be also a bad idea ?
>>
>> Jano
>>
>>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [OT]Threads and Servlets Question
Posted by Vic <vi...@friendvu.com>.
A common solution I use is to have async processes run by cron or
similar to prepare and massage data. A sperate application that runs
every few minutes and dies.
A long time ago it was said "Batch is bread and butter of IT. View is
only the icing on the cake."
.V
Jan Fetyko wrote:
> This is interesting,
>
> let me ask another related question :
>
> What about a thread (started from the Action) that just resizes an image and saves it to a file system ? Would that be also a bad idea ?
>
> Jano
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [OT]Threads and Servlets Question
Posted by bryan <ni...@gmail.com>.
yes, also your better off storing to a database if your using j2ee.
--b
On Mon, 6 Dec 2004 14:39:46 -0600, Jan Fetyko <li...@fetyko.com> wrote:
> This is interesting,
>
> let me ask another related question :
>
> What about a thread (started from the Action) that just resizes an image and saves it to a file system ? Would that be also a bad idea ?
>
> Jano
>
> On Mon, 6 Dec 2004 15:18:12 -0500
>
>
> DGraham@EvergreenInvestments.com wrote:
>
> >I don't understand your response. Memory (physical and virtual) are also
> >finite resources. Does this mean that instantiating new objects is a Bad
> >Thing within an action?
> >
> >Dennis
> >
> >
> >
> >
> >bryan <ni...@gmail.com>
> >12/06/2004 03:14 PM
> >Please respond to
> >"Struts Users Mailing List" <us...@struts.apache.org>
> >
> >
> >To
> >Struts Users Mailing List <us...@struts.apache.org>
> >cc
> >
> >Subject
> >Re: [OT]Threads and Servlets Question
> >
> >
> >
> >
> >
> >
> >threads are also a finite resource ( particularly on Linux ).
> >
> >--b
> >
> >
> >On Mon, 6 Dec 2004 21:13:57 +0100, bryan <ni...@gmail.com> wrote:
> >> because you should use a message driven bean to do something like that.
> >>
> >> --b
> >>
> >>
> >>
> >>
> >> On Mon, 6 Dec 2004 11:48:15 -0700, Jim Barrows <jb...@sssc.com>
> >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: user-unsubscribe@struts.apache.org
> >> > For additional commands, e-mail: user-help@struts.apache.org
> >> >
> >> >
> >>
> >>
> >> --
> >> http://www.revoltingdigits.com
> >> https://jestate.dev.java.net
> >>
> >
> >
> >--
> >http://www.revoltingdigits.com
> >https://jestate.dev.java.net
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >For additional commands, e-mail: user-help@struts.apache.org
> >
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
--
http://www.revoltingdigits.com
https://jestate.dev.java.net
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [OT]Threads and Servlets Question
Posted by Dakota Jack <da...@gmail.com>.
I would encourage this behavior, assuming, of course, that you have
the appropriate knowledge of threads and containers. This is
precisely the sort of thing that I think is really perfect for
multi-threading. If not, I would like to know why not too.
Jack
On Mon, 6 Dec 2004 14:39:46 -0600, Jan Fetyko <li...@fetyko.com> wrote:
> This is interesting,
>
> let me ask another related question :
>
> What about a thread (started from the Action) that just resizes an image and saves it to a file system ? Would that be also a bad idea ?
>
> Jano
>
> On Mon, 6 Dec 2004 15:18:12 -0500
>
>
> DGraham@EvergreenInvestments.com wrote:
>
> >I don't understand your response. Memory (physical and virtual) are also
> >finite resources. Does this mean that instantiating new objects is a Bad
> >Thing within an action?
> >
> >Dennis
> >
> >
> >
> >
> >bryan <ni...@gmail.com>
> >12/06/2004 03:14 PM
> >Please respond to
> >"Struts Users Mailing List" <us...@struts.apache.org>
> >
> >
> >To
> >Struts Users Mailing List <us...@struts.apache.org>
> >cc
> >
> >Subject
> >Re: [OT]Threads and Servlets Question
> >
> >
> >
> >
> >
> >
> >threads are also a finite resource ( particularly on Linux ).
> >
> >--b
> >
> >
> >On Mon, 6 Dec 2004 21:13:57 +0100, bryan <ni...@gmail.com> wrote:
> >> because you should use a message driven bean to do something like that.
> >>
> >> --b
> >>
> >>
> >>
> >>
> >> On Mon, 6 Dec 2004 11:48:15 -0700, Jim Barrows <jb...@sssc.com>
> >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: user-unsubscribe@struts.apache.org
> >> > For additional commands, e-mail: user-help@struts.apache.org
> >> >
> >> >
> >>
> >>
> >> --
> >> http://www.revoltingdigits.com
> >> https://jestate.dev.java.net
> >>
> >
> >
> >--
> >http://www.revoltingdigits.com
> >https://jestate.dev.java.net
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >For additional commands, e-mail: user-help@struts.apache.org
> >
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
--
"You can't wake a person who is pretending to be asleep."
~Native Proverb~
"Each man is good in His sight. It is not necessary for eagles to be crows."
~Hunkesni (Sitting Bull), Hunkpapa Sioux~
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [OT]Threads and Servlets Question
Posted by Jan Fetyko <li...@fetyko.com>.
This is interesting,
let me ask another related question :
What about a thread (started from the Action) that just resizes an image and saves it to a file system ? Would that be also a bad idea ?
Jano
On Mon, 6 Dec 2004 15:18:12 -0500
DGraham@EvergreenInvestments.com wrote:
>I don't understand your response. Memory (physical and virtual) are also
>finite resources. Does this mean that instantiating new objects is a Bad
>Thing within an action?
>
>Dennis
>
>
>
>
>bryan <ni...@gmail.com>
>12/06/2004 03:14 PM
>Please respond to
>"Struts Users Mailing List" <us...@struts.apache.org>
>
>
>To
>Struts Users Mailing List <us...@struts.apache.org>
>cc
>
>Subject
>Re: [OT]Threads and Servlets Question
>
>
>
>
>
>
>threads are also a finite resource ( particularly on Linux ).
>
>--b
>
>
>On Mon, 6 Dec 2004 21:13:57 +0100, bryan <ni...@gmail.com> wrote:
>> because you should use a message driven bean to do something like that.
>>
>> --b
>>
>>
>>
>>
>> On Mon, 6 Dec 2004 11:48:15 -0700, Jim Barrows <jb...@sssc.com>
>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: user-unsubscribe@struts.apache.org
>> > For additional commands, e-mail: user-help@struts.apache.org
>> >
>> >
>>
>>
>> --
>> http://www.revoltingdigits.com
>> https://jestate.dev.java.net
>>
>
>
>--
>http://www.revoltingdigits.com
>https://jestate.dev.java.net
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [OT]Threads and Servlets Question
Posted by DG...@EvergreenInvestments.com.
I don't understand your response. Memory (physical and virtual) are also
finite resources. Does this mean that instantiating new objects is a Bad
Thing within an action?
Dennis
bryan <ni...@gmail.com>
12/06/2004 03:14 PM
Please respond to
"Struts Users Mailing List" <us...@struts.apache.org>
To
Struts Users Mailing List <us...@struts.apache.org>
cc
Subject
Re: [OT]Threads and Servlets Question
threads are also a finite resource ( particularly on Linux ).
--b
On Mon, 6 Dec 2004 21:13:57 +0100, bryan <ni...@gmail.com> wrote:
> because you should use a message driven bean to do something like that.
>
> --b
>
>
>
>
> On Mon, 6 Dec 2004 11:48:15 -0700, Jim Barrows <jb...@sssc.com>
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: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>
>
> --
> http://www.revoltingdigits.com
> https://jestate.dev.java.net
>
--
http://www.revoltingdigits.com
https://jestate.dev.java.net
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [OT]Threads and Servlets Question
Posted by bryan <ni...@gmail.com>.
threads are also a finite resource ( particularly on Linux ).
--b
On Mon, 6 Dec 2004 21:13:57 +0100, bryan <ni...@gmail.com> wrote:
> because you should use a message driven bean to do something like that.
>
> --b
>
>
>
>
> On Mon, 6 Dec 2004 11:48:15 -0700, Jim Barrows <jb...@sssc.com> 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: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>
>
> --
> http://www.revoltingdigits.com
> https://jestate.dev.java.net
>
--
http://www.revoltingdigits.com
https://jestate.dev.java.net
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [OT]Threads and Servlets Question
Posted by bryan <ni...@gmail.com>.
because you should use a message driven bean to do something like that.
--b
On Mon, 6 Dec 2004 11:48:15 -0700, Jim Barrows <jb...@sssc.com> 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: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
--
http://www.revoltingdigits.com
https://jestate.dev.java.net
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [OT]Threads and Servlets Question
Posted by Dakota Jack <da...@gmail.com>.
The only reason for me to have any contact with the container is to
make resources available to the container.
Jack
On Tue, 07 Dec 2004 13:41:06 +0800, Andrew Hill
<an...@gridnode.com> wrote:
> <snip>
> I would never, of course, dream of grabbing a request object, or
> similar things, and holding it in a new thread. I would never, ever,
> anytime dream of doing that. Yuk!
> </snip>
>
> hehe.
> What about the ServletContext object though?
>
>
>
> Dakota Jack wrote:
>
> > Spawning threads is something I do almost as a matter of course in my
> > programming. I don't know what I would do without doing that.
> >
> > I would never, of course, dream of grabbing a request object, or
> > similar things, and holding it in a new thread. I would never, ever,
> > anytime dream of doing that. Yuk!
> >
> > As those who have noted my submissions to this list will know, I am
> > big on state management outside the request, page, session and
> > application scopes and this seems to almost necessarily involve
> > threads in the solutions my head devises. I also make extensive use
> > of Doug Lea's work which is essentially multi-threading.
> >
> > Like everything else, you can code threads well and badly. I guess
> > the upshot of bad coding with threads is particularly serious, so you
> > don't want newcomers being assigned these tasks?
> >
> > Jack
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
--
"You can't wake a person who is pretending to be asleep."
~Native Proverb~
"Each man is good in His sight. It is not necessary for eagles to be crows."
~Hunkesni (Sitting Bull), Hunkpapa Sioux~
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [OT]Threads and Servlets Question
Posted by Craig McClanahan <cr...@gmail.com>.
On Tue, 07 Dec 2004 13:41:06 +0800, Andrew Hill
<an...@gridnode.com> wrote:
> <snip>
> I would never, of course, dream of grabbing a request object, or
> similar things, and holding it in a new thread. I would never, ever,
> anytime dream of doing that. Yuk!
> </snip>
>
> hehe.
> What about the ServletContext object though?
>
Did you remember to shut down your thread when your app was
undeployed? If not then the thread's reference you have to a
ServletContext object is likely to be stale. :-)
On the other hand, I can't remember any guarantees that the object
reference returned by Servlet.getServletContext() is defined to be the
same for all invocations, even through the lifetime of a single app
without considering reloads.
Or, on the other hand, what happens if you are running on a
distributed server, and a particular user session gets migrated from
one server instance to another. The fact that you might have started
a thread on server instance A doesn't help much when your application
code running on server B tries to queue something up to it.
I tend to be a conservative -- only pass references to objects that
*you* control the lifetime of, such as servlet context attributes,
rather than the ServletContext instance itself. That way, you can use
the listener APIs provided by your servlet container (2.3 or later) to
clean up threads at appropriate times, without having to hope that
your container isn't
As an incentive to be a good boy or girl in this regard, decoupling
your thread code from the servlet API makes it a lot easier to build
unit tests :-).
Craig
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [OT]Threads and Servlets Question
Posted by Andrew Hill <an...@gridnode.com>.
<snip>
I would never, of course, dream of grabbing a request object, or
similar things, and holding it in a new thread. I would never, ever,
anytime dream of doing that. Yuk!
</snip>
hehe.
What about the ServletContext object though?
Dakota Jack wrote:
> Spawning threads is something I do almost as a matter of course in my
> programming. I don't know what I would do without doing that.
>
> I would never, of course, dream of grabbing a request object, or
> similar things, and holding it in a new thread. I would never, ever,
> anytime dream of doing that. Yuk!
>
> As those who have noted my submissions to this list will know, I am
> big on state management outside the request, page, session and
> application scopes and this seems to almost necessarily involve
> threads in the solutions my head devises. I also make extensive use
> of Doug Lea's work which is essentially multi-threading.
>
> Like everything else, you can code threads well and badly. I guess
> the upshot of bad coding with threads is particularly serious, so you
> don't want newcomers being assigned these tasks?
>
> Jack
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [OT]Threads and Servlets Question
Posted by Dakota Jack <da...@gmail.com>.
Spawning threads is something I do almost as a matter of course in my
programming. I don't know what I would do without doing that.
I would never, of course, dream of grabbing a request object, or
similar things, and holding it in a new thread. I would never, ever,
anytime dream of doing that. Yuk!
As those who have noted my submissions to this list will know, I am
big on state management outside the request, page, session and
application scopes and this seems to almost necessarily involve
threads in the solutions my head devises. I also make extensive use
of Doug Lea's work which is essentially multi-threading.
Like everything else, you can code threads well and badly. I guess
the upshot of bad coding with threads is particularly serious, so you
don't want newcomers being assigned these tasks?
Jack
--
"You can't wake a person who is pretending to be asleep."
~Native Proverb~
"Each man is good in His sight. It is not necessary for eagles to be crows."
~Hunkesni (Sitting Bull), Hunkpapa Sioux~
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [OT]Threads and Servlets Question
Posted by Craig McClanahan <cr...@gmail.com>.
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.
Craig
On Mon, 6 Dec 2004 11:48:15 -0700, Jim Barrows <jb...@sssc.com> 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: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org