Erkan,

> When I now login to my app it does 3 ajax calls to the action bean (almost concurrently).

You'll need to post enough relevant code for us to see what exactly you are doing and what could be wrong.

As far as @SessionScope is concerned... the 1st time a bean used it is added to the session scope of the user... does not appear (at least from the wording in the docs without examining the code) to necessarily guarantee you won't end up with a few different instances if you get concurrent calls... which in itself shouldn't be much of an issue as the same user doesn't typically fire multiple concurrent requests.

In the end, I would suggest moving your initialization code into a Singleton class or Spring bean (default is Singleton) that internally constructor pre-inits and that is referenced from your Action Bean and voila exactly one initialization. You could even add a hook for re-initialization.

Lastly, there are some down sides (see below from code) at least in the docs on @SessionScope usage - yes, we all want to reduce unnecessary object creation and garbage collection - but I think the downsides of @SessionScope are enough to accept taking the additional object creation / cleanup unless Profiling of your application tells you this is your bottleneck.

--Nikolaos

* <p>Annotation that is used to specify that an ActionBean should be instantiated and stored across * requests in the Session scope. By default ActionBeans are instantiated per-request, populated, * used and then discarded at the end of the request cycle. Using this annotation causes an * ActionBean to live for multiple request cycles. It will be instantiated and put into session * on the first request that references the ActionBean. A reference to the bean will also be * placed into RequestScope for each request that references the bean, thereby allowing the rest
* of Stripes to treat it like any other ActionBean.</p>
*
* <p>Since session scope ActionBeans are not generally encouraged by the author, very few * allowances will be made in Stripes to accommodate session scope beans. This means that * additional mechanisms to handle session scope beans do not exist. However, there are * general mechanisms built in to Stripes that will allow you to overcome most if not all issues
* that arise from Session scoping ActionBeans.</p>
*
* <p>One major issue is how to clear out values from an ActionBean before the next request cycle. * It is suggested that this be done in the ActionBean.setContext() method, which is guaranteed to * be invoked before any binding occurs. Note that this problem is two-fold. Firstly the browser * does not submit values for checkboxes that are de-selected. Secondly Stripes does not invoke * setters for parameters submitted in the request with values equal to the empty-string. You may * choose to simply null out such fields in setContext() or use the available reference to the * HttpServletRequest to find out if empty values were submitted for fields, and null out just
* those fields.</p>
*
* <p>A second major issue is in using the validation service. The validation service validates * <em>what was submitted in the request</em>. Therefore if a property is marked are required, * is present in the session scope bean, but is not submitted by the user, it will generate a * required field error. This may or may not be desired behaviour. If it is not, it is suggested * that the ActionBean implement the ValidationErrorHandler interface to find out about the
* validation errors generated, and take action accordingly.</p>
*
* <p>Lastly, an alternative to session scoping for wizard pattern/page-spanning forms that
* ActionBean authors may wish to consider is the use of the
* {...@link net.sourceforge.stripes.tag.WizardFieldsTag} which will carry all the fields submitted
* in the request into the next request by writing hidden form fields.</p>




Erkan Kör wrote:
Hi Marcus,

I just verified it and the same JSESSIONID is passed with all three ajax calls. So it must be something different-

> Date: Wed, 9 Jun 2010 14:42:03 +0200
> From: m...@syn-online.de
> To: stripes-users@lists.sourceforge.net
> Subject: Re: [Stripes-users] Concurrent call problem with @SessionScope annotation
>
> Hi Erkan,
>
>
> Am 09.06.2010 14:30, schrieb Erkan Kör:
> > I have an action bean with the @SessionScope annotation. In the
> > ActionBean constructor I do few initializations. When I now login to
> > my app it does 3 ajax calls to the action bean (almost concurrently).
> > But somehow the constructor is called 3 times. But when my frontend
> > calls the methods one after another it works.
>
> I think that you don't pass any session parameters with your AJAX calls,
> so there is no chance to save and retrieve the action bean from your
> existing session. Later on, when you call explicit methods by using the
> usual request/response cycle, your request contains a cookie wirh your
> session id, so the session-scoped action bean can be reused.
>
> HTH,
> Marcus
>
> ------------------------------------------------------------------------------
> ThinkGeek and WIRED's GeekDad team up for the Ultimate
> GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the
> lucky parental unit. See the prize list and enter to win:
> http://p.sf.net/sfu/thinkgeek-promo
> _______________________________________________
> Stripes-users mailing list
> Stripes-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/stripes-users

------------------------------------------------------------------------
Your E-mail and More On-the-Go. Get Windows Live Hotmail Free. Sign up now. <https://signup.live.com/signup.aspx?id=60969>
------------------------------------------------------------------------

------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the lucky parental unit. See the prize list and enter to win: http://p.sf.net/sfu/thinkgeek-promo
------------------------------------------------------------------------

_______________________________________________
Stripes-users mailing list
Stripes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/stripes-users


------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate 
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the 
lucky parental unit.  See the prize list and enter to win: 
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
Stripes-users mailing list
Stripes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/stripes-users

Reply via email to