You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Sekar, Sowmya" <ss...@ucsd.edu> on 2014/11/04 22:08:42 UTC

Struts 1 Thread safe action classes

Hi,

To invoke service classes from each method in the action classes, are there any other options to make it thread safe other than initializing them as local variables?

Thanks, Sowmya

Re: Struts 1 Thread safe action classes

Posted by Paul Benedict <pb...@apache.org>.
Instantiating a new action class per request is not a bad idea. It's not
standard but not bad. Struts 2 does this, I think Spring MVC does this, and
a host of other web frameworks.


Cheers,
Paul

On Tue, Nov 4, 2014 at 3:20 PM, Eric Reed <Er...@nysed.gov> wrote:

> As Paul said, you must avoid instance variables in Struts 1.
>
> I once had a HUGE project that was written with Struts 1. Along with
> terrible code I saw instance variables everywhere. I think over 650 action
> classes with instance variables so I just re-wrote a few lines in the
> latest Struts 1 source code and initialized a new action for every
> request.  It shot up the server memory by a bunch but who cares, memory is
> cheap compared to me re-writing all those classes.
>
> Regards,
> Eric
>
>
>
>
> -----Original Message-----
> From: Paul Benedict [mailto:pbenedict@apache.org]
> Sent: Tuesday, November 04, 2014 4:16 PM
> To: Struts Users Mailing List
> Subject: Re: Struts 1 Thread safe action classes
>
> To be thread safe, your services should never store user data in instance
> variables. That's all there is to it. Keep everything local.
>
>
> Cheers,
> Paul
>
> On Tue, Nov 4, 2014 at 3:14 PM, Sekar, Sowmya <ss...@ucsd.edu> wrote:
>
> > How do I accomplish that?
> >
> > -----Original Message-----
> > From: Paul Benedict [mailto:pbenedict@apache.org]
> > Sent: Tuesday, November 04, 2014 1:13 PM
> > To: Struts Users Mailing List
> > Subject: Re: Struts 1 Thread safe action classes
> >
> > Your service classes should be thread-safe to begin with. You don't
> > need multiple instances of a business service.
> >
> >
> > Cheers,
> > Paul
> >
> > On Tue, Nov 4, 2014 at 3:08 PM, Sekar, Sowmya <ss...@ucsd.edu> wrote:
> >
> > > Hi,
> > >
> > > To invoke service classes from each method in the action classes,
> > > are there any other options to make it thread safe other than
> > > initializing them as local variables?
> > >
> > > Thanks, Sowmya
> > >
> >
>

RE: Struts 1 Thread safe action classes

Posted by Eric Reed <Er...@nysed.gov>.
As Paul said, you must avoid instance variables in Struts 1. 

I once had a HUGE project that was written with Struts 1. Along with terrible code I saw instance variables everywhere. I think over 650 action classes with instance variables so I just re-wrote a few lines in the latest Struts 1 source code and initialized a new action for every request.  It shot up the server memory by a bunch but who cares, memory is cheap compared to me re-writing all those classes.

Regards,
Eric




-----Original Message-----
From: Paul Benedict [mailto:pbenedict@apache.org] 
Sent: Tuesday, November 04, 2014 4:16 PM
To: Struts Users Mailing List
Subject: Re: Struts 1 Thread safe action classes

To be thread safe, your services should never store user data in instance variables. That's all there is to it. Keep everything local.


Cheers,
Paul

On Tue, Nov 4, 2014 at 3:14 PM, Sekar, Sowmya <ss...@ucsd.edu> wrote:

> How do I accomplish that?
>
> -----Original Message-----
> From: Paul Benedict [mailto:pbenedict@apache.org]
> Sent: Tuesday, November 04, 2014 1:13 PM
> To: Struts Users Mailing List
> Subject: Re: Struts 1 Thread safe action classes
>
> Your service classes should be thread-safe to begin with. You don't 
> need multiple instances of a business service.
>
>
> Cheers,
> Paul
>
> On Tue, Nov 4, 2014 at 3:08 PM, Sekar, Sowmya <ss...@ucsd.edu> wrote:
>
> > Hi,
> >
> > To invoke service classes from each method in the action classes, 
> > are there any other options to make it thread safe other than 
> > initializing them as local variables?
> >
> > Thanks, Sowmya
> >
>

Re: Struts 1 Thread safe action classes

Posted by Paul Benedict <pb...@apache.org>.
To be thread safe, your services should never store user data in instance
variables. That's all there is to it. Keep everything local.


Cheers,
Paul

On Tue, Nov 4, 2014 at 3:14 PM, Sekar, Sowmya <ss...@ucsd.edu> wrote:

> How do I accomplish that?
>
> -----Original Message-----
> From: Paul Benedict [mailto:pbenedict@apache.org]
> Sent: Tuesday, November 04, 2014 1:13 PM
> To: Struts Users Mailing List
> Subject: Re: Struts 1 Thread safe action classes
>
> Your service classes should be thread-safe to begin with. You don't need
> multiple instances of a business service.
>
>
> Cheers,
> Paul
>
> On Tue, Nov 4, 2014 at 3:08 PM, Sekar, Sowmya <ss...@ucsd.edu> wrote:
>
> > Hi,
> >
> > To invoke service classes from each method in the action classes, are
> > there any other options to make it thread safe other than initializing
> > them as local variables?
> >
> > Thanks, Sowmya
> >
>

RE: Struts 1 Thread safe action classes

Posted by "Sekar, Sowmya" <ss...@ucsd.edu>.
How do I accomplish that?

-----Original Message-----
From: Paul Benedict [mailto:pbenedict@apache.org] 
Sent: Tuesday, November 04, 2014 1:13 PM
To: Struts Users Mailing List
Subject: Re: Struts 1 Thread safe action classes

Your service classes should be thread-safe to begin with. You don't need multiple instances of a business service.


Cheers,
Paul

On Tue, Nov 4, 2014 at 3:08 PM, Sekar, Sowmya <ss...@ucsd.edu> wrote:

> Hi,
>
> To invoke service classes from each method in the action classes, are 
> there any other options to make it thread safe other than initializing 
> them as local variables?
>
> Thanks, Sowmya
>

Re: Struts 1 Thread safe action classes

Posted by Paul Benedict <pb...@apache.org>.
Your service classes should be thread-safe to begin with. You don't need
multiple instances of a business service.


Cheers,
Paul

On Tue, Nov 4, 2014 at 3:08 PM, Sekar, Sowmya <ss...@ucsd.edu> wrote:

> Hi,
>
> To invoke service classes from each method in the action classes, are
> there any other options to make it thread safe other than initializing them
> as local variables?
>
> Thanks, Sowmya
>