You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by rohit <ro...@in-rev.com> on 2012/11/29 16:29:01 UTC

Struts2 String ThreadSafe?

 Hi,
   We are using Struts2-Spring integration and all my action classes implement SessionAware, sample code to action class and their spring definition is given below,
 public class IRXxxxAction extends ActionSupport implements SessionAware { private Map session; public String execute() {//} public void setSession(Map&lt;String, Object&gt; session) { this.session = session; } }  Spring Configuration
 &lt;bean name="userAction" class="com.IRXxxxAction" &gt; &lt;property name="adminDAO" ref="adminDAO" /&gt; &lt;/bean&gt; If I understand correctly, each auto-wired property will be a singleton, so if the above is true, is there anyway that the session map get shared between two simultaneous requests?
 Regards,


 



Re: Struts2 String ThreadSafe?

Posted by Dave Newton <da...@gmail.com>.
On Thu, Nov 29, 2012 at 2:01 PM, Eric Reed wrote:
> Using "global / instance" variables is a bad coding practice you should kick now and should be avoided  unless you are defining something final static such as a log file.

Just to be clear: the entire S2 framework is predicated on instance
variables as  action properties for the view layer. Properties beyond
that are developer's choice, but S2 is built on the idea of an
action-per-request.

Dave

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts2 String ThreadSafe?

Posted by Eric Reed <ER...@MAIL.NYSED.GOV>.
This was a problem with Struts 1.3 which reuses action classes. On a large project I took over the only real solution was to open up the Struts 1.3 source and re-code it because the app was too big to replace all the instance variables.

Using "global / instance" variables is a bad coding practice you should kick now and should be avoided  unless you are defining something final static such as a log file.

Eric 

>>> Dave Newton <da...@gmail.com> 11/29/2012 10:54 AM >>>
Correct: if an action isn't instantiated per-request, obviously
instance variables will be shared across requests.

Dave

On Thu, Nov 29, 2012 at 10:51 AM, rohit <ro...@in-rev.com> wrote:
> So in the current case there is a chance that same action class may be used in simultaneous request and hence the mixup?
>
>
>
> ---- On Thu, 29 Nov 2012 21:02:23 +0530 Umesh Awasthi &lt;umeshawasthi@gmail.com&gt; wrote ----
>
>
> First and foremost for using spring with Struts2 make your action bean
> scope prototype
> and is not be ready for the weird issues
>
> Struts2 itself create a new request instance as well other objects
> associated with itself to make it thread safe.
>
>
>
> On Thu, Nov 29, 2012 at 8:59 PM, rohit &lt;rohit@in-rev.com&gt; wrote:
>
> &gt; Hi,
> &gt; We are using Struts2-Spring integration and all my action classes
> &gt; implement SessionAware, sample code to action class and their spring
> &gt; definition is given below,
> &gt; public class IRXxxxAction extends ActionSupport implements SessionAware {
> &gt; private Map session; public String execute() {//} public void
> &gt; setSession(Map&amp;lt;String, Object&amp;gt; session) { this.session = session; } }
> &gt; Spring Configuration
> &gt; &amp;lt;bean name="userAction" class="com.IRXxxxAction" &amp;gt; &amp;lt;property
> &gt; name="adminDAO" ref="adminDAO" /&amp;gt; &amp;lt;/bean&amp;gt; If I understand
> &gt; correctly, each auto-wired property will be a singleton, so if the above is
> &gt; true, is there anyway that the session map get shared between two
> &gt; simultaneous requests?
> &gt; Regards,
> &gt;
> &gt;
> &gt;
> &gt;
> &gt;
> &gt;
>
>
> --
> With Regards
> Umesh Awasthi
> http://www.travellingrants.com/ 
>
>



-- 
e: davelnewton@gmail.com 
m: 908-380-8699
s: davelnewton_skype
t: @dave_newton
b: Bucky Bits
g: davelnewton
so: Dave Newton

---------------------------------------------------------------------
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: Struts2 String ThreadSafe?

Posted by Dave Newton <da...@gmail.com>.
Correct: if an action isn't instantiated per-request, obviously
instance variables will be shared across requests.

Dave

On Thu, Nov 29, 2012 at 10:51 AM, rohit <ro...@in-rev.com> wrote:
> So in the current case there is a chance that same action class may be used in simultaneous request and hence the mixup?
>
>
>
> ---- On Thu, 29 Nov 2012 21:02:23 +0530 Umesh Awasthi &lt;umeshawasthi@gmail.com&gt; wrote ----
>
>
> First and foremost for using spring with Struts2 make your action bean
> scope prototype
> and is not be ready for the weird issues
>
> Struts2 itself create a new request instance as well other objects
> associated with itself to make it thread safe.
>
>
>
> On Thu, Nov 29, 2012 at 8:59 PM, rohit &lt;rohit@in-rev.com&gt; wrote:
>
> &gt; Hi,
> &gt; We are using Struts2-Spring integration and all my action classes
> &gt; implement SessionAware, sample code to action class and their spring
> &gt; definition is given below,
> &gt; public class IRXxxxAction extends ActionSupport implements SessionAware {
> &gt; private Map session; public String execute() {//} public void
> &gt; setSession(Map&amp;lt;String, Object&amp;gt; session) { this.session = session; } }
> &gt; Spring Configuration
> &gt; &amp;lt;bean name="userAction" class="com.IRXxxxAction" &amp;gt; &amp;lt;property
> &gt; name="adminDAO" ref="adminDAO" /&amp;gt; &amp;lt;/bean&amp;gt; If I understand
> &gt; correctly, each auto-wired property will be a singleton, so if the above is
> &gt; true, is there anyway that the session map get shared between two
> &gt; simultaneous requests?
> &gt; Regards,
> &gt;
> &gt;
> &gt;
> &gt;
> &gt;
> &gt;
>
>
> --
> With Regards
> Umesh Awasthi
> http://www.travellingrants.com/
>
>



-- 
e: davelnewton@gmail.com
m: 908-380-8699
s: davelnewton_skype
t: @dave_newton
b: Bucky Bits
g: davelnewton
so: Dave Newton

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts2 String ThreadSafe?

Posted by rohit <ro...@in-rev.com>.
So in the current case there is a chance that same action class may be used in simultaneous request and hence the mixup?



---- On Thu, 29 Nov 2012 21:02:23 +0530 Umesh Awasthi &lt;umeshawasthi@gmail.com&gt; wrote ---- 


First and foremost for using spring with Struts2 make your action bean 
scope prototype 
and is not be ready for the weird issues 
 
Struts2 itself create a new request instance as well other objects 
associated with itself to make it thread safe. 
 
 
 
On Thu, Nov 29, 2012 at 8:59 PM, rohit &lt;rohit@in-rev.com&gt; wrote: 
 
&gt; Hi, 
&gt; We are using Struts2-Spring integration and all my action classes 
&gt; implement SessionAware, sample code to action class and their spring 
&gt; definition is given below, 
&gt; public class IRXxxxAction extends ActionSupport implements SessionAware { 
&gt; private Map session; public String execute() {//} public void 
&gt; setSession(Map&amp;lt;String, Object&amp;gt; session) { this.session = session; } } 
&gt; Spring Configuration 
&gt; &amp;lt;bean name="userAction" class="com.IRXxxxAction" &amp;gt; &amp;lt;property 
&gt; name="adminDAO" ref="adminDAO" /&amp;gt; &amp;lt;/bean&amp;gt; If I understand 
&gt; correctly, each auto-wired property will be a singleton, so if the above is 
&gt; true, is there anyway that the session map get shared between two 
&gt; simultaneous requests? 
&gt; Regards, 
&gt; 
&gt; 
&gt; 
&gt; 
&gt; 
&gt; 
 
 
-- 
With Regards 
Umesh Awasthi 
http://www.travellingrants.com/ 



Re: Struts2 String ThreadSafe?

Posted by "J. Garcia" <jo...@gmail.com>.
This is definitely wrong. You can mix data from two different concurrent
sessions!



On Thu, Nov 29, 2012 at 4:42 PM, Rohit Gupta <ro...@simplify360.com> wrote:

> So given the fact that my beans are not prototype, there is a chance that
> the same action class may be used for two consecutive requests.
>
> Regards,
>
>
> On 29/11/12 9:02 PM, "Umesh Awasthi" <um...@gmail.com> wrote:
>
> >First and foremost for using spring with Struts2 make your action bean
> >scope prototype
> >and is not be ready for the weird issues
> >
> >Struts2 itself create a new request instance as well other objects
> >associated with itself to make it thread safe.
> >
> >
> >
> >On Thu, Nov 29, 2012 at 8:59 PM, rohit <ro...@in-rev.com> wrote:
> >
> >>  Hi,
> >>    We are using Struts2-Spring integration and all my action classes
> >> implement SessionAware, sample code to action class and their spring
> >> definition is given below,
> >>  public class IRXxxxAction extends ActionSupport implements
> >>SessionAware {
> >> private Map session; public String execute() {//} public void
> >> setSession(Map&lt;String, Object&gt; session) { this.session = session;
> >>} }
> >>  Spring Configuration
> >>  &lt;bean name="userAction" class="com.IRXxxxAction" &gt; &lt;property
> >> name="adminDAO" ref="adminDAO" /&gt; &lt;/bean&gt; If I understand
> >> correctly, each auto-wired property will be a singleton, so if the
> >>above is
> >> true, is there anyway that the session map get shared between two
> >> simultaneous requests?
> >>  Regards,
> >>
> >>
> >>
> >>
> >>
> >>
> >
> >
> >--
> >With Regards
> >Umesh Awasthi
> >http://www.travellingrants.com/
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Struts2 String ThreadSafe?

Posted by Umesh Awasthi <um...@gmail.com>.
I believe you should look more in to more spring doc to see how spring
provide instance based on the scope provided for the bean.

Struts2-Spring integration is only providing bridge where in place of
struts internal DI, Spring is handling DI for you but rest of the flow and
concepts will be same

Thanks
Umesh

On Fri, Nov 30, 2012 at 12:25 PM, Chris Pratt <th...@gmail.com>wrote:

> It's not a chance, the same instance is being used for all requests to that
> action.
>   (*Chris*)
>
>
> On Thu, Nov 29, 2012 at 7:42 AM, Rohit Gupta <ro...@simplify360.com>
> wrote:
>
> > So given the fact that my beans are not prototype, there is a chance that
> > the same action class may be used for two consecutive requests.
> >
> > Regards,
> >
> >
> > On 29/11/12 9:02 PM, "Umesh Awasthi" <um...@gmail.com> wrote:
> >
> > >First and foremost for using spring with Struts2 make your action bean
> > >scope prototype
> > >and is not be ready for the weird issues
> > >
> > >Struts2 itself create a new request instance as well other objects
> > >associated with itself to make it thread safe.
> > >
> > >
> > >
> > >On Thu, Nov 29, 2012 at 8:59 PM, rohit <ro...@in-rev.com> wrote:
> > >
> > >>  Hi,
> > >>    We are using Struts2-Spring integration and all my action classes
> > >> implement SessionAware, sample code to action class and their spring
> > >> definition is given below,
> > >>  public class IRXxxxAction extends ActionSupport implements
> > >>SessionAware {
> > >> private Map session; public String execute() {//} public void
> > >> setSession(Map&lt;String, Object&gt; session) { this.session =
> session;
> > >>} }
> > >>  Spring Configuration
> > >>  &lt;bean name="userAction" class="com.IRXxxxAction" &gt; &lt;property
> > >> name="adminDAO" ref="adminDAO" /&gt; &lt;/bean&gt; If I understand
> > >> correctly, each auto-wired property will be a singleton, so if the
> > >>above is
> > >> true, is there anyway that the session map get shared between two
> > >> simultaneous requests?
> > >>  Regards,
> > >>
> > >>
> > >>
> > >>
> > >>
> > >>
> > >
> > >
> > >--
> > >With Regards
> > >Umesh Awasthi
> > >http://www.travellingrants.com/
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>



-- 
With Regards
Umesh Awasthi
http://www.travellingrants.com/

Re: Struts2 String ThreadSafe?

Posted by Chris Pratt <th...@gmail.com>.
It's not a chance, the same instance is being used for all requests to that
action.
  (*Chris*)


On Thu, Nov 29, 2012 at 7:42 AM, Rohit Gupta <ro...@simplify360.com> wrote:

> So given the fact that my beans are not prototype, there is a chance that
> the same action class may be used for two consecutive requests.
>
> Regards,
>
>
> On 29/11/12 9:02 PM, "Umesh Awasthi" <um...@gmail.com> wrote:
>
> >First and foremost for using spring with Struts2 make your action bean
> >scope prototype
> >and is not be ready for the weird issues
> >
> >Struts2 itself create a new request instance as well other objects
> >associated with itself to make it thread safe.
> >
> >
> >
> >On Thu, Nov 29, 2012 at 8:59 PM, rohit <ro...@in-rev.com> wrote:
> >
> >>  Hi,
> >>    We are using Struts2-Spring integration and all my action classes
> >> implement SessionAware, sample code to action class and their spring
> >> definition is given below,
> >>  public class IRXxxxAction extends ActionSupport implements
> >>SessionAware {
> >> private Map session; public String execute() {//} public void
> >> setSession(Map&lt;String, Object&gt; session) { this.session = session;
> >>} }
> >>  Spring Configuration
> >>  &lt;bean name="userAction" class="com.IRXxxxAction" &gt; &lt;property
> >> name="adminDAO" ref="adminDAO" /&gt; &lt;/bean&gt; If I understand
> >> correctly, each auto-wired property will be a singleton, so if the
> >>above is
> >> true, is there anyway that the session map get shared between two
> >> simultaneous requests?
> >>  Regards,
> >>
> >>
> >>
> >>
> >>
> >>
> >
> >
> >--
> >With Regards
> >Umesh Awasthi
> >http://www.travellingrants.com/
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Struts2 String ThreadSafe?

Posted by Rohit Gupta <ro...@simplify360.com>.
So given the fact that my beans are not prototype, there is a chance that
the same action class may be used for two consecutive requests.

Regards,


On 29/11/12 9:02 PM, "Umesh Awasthi" <um...@gmail.com> wrote:

>First and foremost for using spring with Struts2 make your action bean
>scope prototype
>and is not be ready for the weird issues
>
>Struts2 itself create a new request instance as well other objects
>associated with itself to make it thread safe.
>
>
>
>On Thu, Nov 29, 2012 at 8:59 PM, rohit <ro...@in-rev.com> wrote:
>
>>  Hi,
>>    We are using Struts2-Spring integration and all my action classes
>> implement SessionAware, sample code to action class and their spring
>> definition is given below,
>>  public class IRXxxxAction extends ActionSupport implements
>>SessionAware {
>> private Map session; public String execute() {//} public void
>> setSession(Map&lt;String, Object&gt; session) { this.session = session;
>>} }
>>  Spring Configuration
>>  &lt;bean name="userAction" class="com.IRXxxxAction" &gt; &lt;property
>> name="adminDAO" ref="adminDAO" /&gt; &lt;/bean&gt; If I understand
>> correctly, each auto-wired property will be a singleton, so if the
>>above is
>> true, is there anyway that the session map get shared between two
>> simultaneous requests?
>>  Regards,
>>
>>
>>
>>
>>
>>
>
>
>-- 
>With Regards
>Umesh Awasthi
>http://www.travellingrants.com/




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts2 String ThreadSafe?

Posted by Umesh Awasthi <um...@gmail.com>.
First and foremost for using spring with Struts2 make your action bean
scope prototype
and is not be ready for the weird issues

Struts2 itself create a new request instance as well other objects
associated with itself to make it thread safe.



On Thu, Nov 29, 2012 at 8:59 PM, rohit <ro...@in-rev.com> wrote:

>  Hi,
>    We are using Struts2-Spring integration and all my action classes
> implement SessionAware, sample code to action class and their spring
> definition is given below,
>  public class IRXxxxAction extends ActionSupport implements SessionAware {
> private Map session; public String execute() {//} public void
> setSession(Map&lt;String, Object&gt; session) { this.session = session; } }
>  Spring Configuration
>  &lt;bean name="userAction" class="com.IRXxxxAction" &gt; &lt;property
> name="adminDAO" ref="adminDAO" /&gt; &lt;/bean&gt; If I understand
> correctly, each auto-wired property will be a singleton, so if the above is
> true, is there anyway that the session map get shared between two
> simultaneous requests?
>  Regards,
>
>
>
>
>
>


-- 
With Regards
Umesh Awasthi
http://www.travellingrants.com/