You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Paulo Andrade <pf...@mega.ist.utl.pt> on 2010/11/01 14:43:28 UTC

Session concurrency

Hello,

Sorry if this an easy question, but I'm new to tapestry and couldn't quite figure out how does tapestry handle sessions. My main worry is concurrent access to session objects.

If two request for the same session arrive simultaneously, will the session object be accessed concurrently in two threads?

Take the following code:

______
@SessionState
Foo someSessionObject;
bool someSessionObjectExists; 

(…)

if( !someSessionObjectExists ){
	someSessionObject = getSomeSessionObject();
}
______

If two request with the same session execute that if statement the getSomeSessionObject() might be called twice and thus creating two objects.

Coming form WebObjects I usually don't have to worry about this because I know that two threads are never accessing the same Session object simultaneously. All session access is serialized.

So how does this work with tapestry?

PS: I'm playing with Tapestry 5.2.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Session concurrency

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Mon, 01 Nov 2010 11:43:28 -0200, Paulo Andrade <pf...@mega.ist.utl.pt>  
wrote:

> Hello,

Hi!

> Sorry if this an easy question,

It isn't. Actually, it's not even a Tapestry-only problem, but of stateful  
web applications too.

> but I'm new to tapestry and couldn't quite figure out how does tapestry  
> handle sessions.

Tapestry just delegates to an HttpSession.

> If two request for the same session arrive simultaneously, will the  
> session object be accessed concurrently in two threads?

Yes, as in (almost) any other Java web app.

> Take the following code:
>
> ______
> @SessionState
> Foo someSessionObject;
> bool someSessionObjectExists;
> if( !someSessionObjectExists ){
> 	someSessionObject = getSomeSessionObject();
> }

You can use @SessionState(create = null) and check if someSessionObject is  
null directly.

> If two request with the same session execute that if statement the  
> getSomeSessionObject() might be called twice and thus creating two  
> objects.

Yes, but only one will be used, as both will be mapped to the same session  
attribute name.

> Coming form WebObjects I usually don't have to worry about this because  
> I know that two threads are never accessing the same Session object  
> simultaneously. All session access is serialized.
> So how does this work with tapestry?

Tapestry nor the Servlet API synchronize access to the session.

>
> PS: I'm playing with Tapestry 5.2.
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>


-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
Consultor, desenvolvedor e instrutor em Java, Tapestry e Hibernate
Coordenador e professor da Especialização em Engenharia de Software com  
Ênfase em Java da Faculdade Pitágoras
http://www.arsmachina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org