You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Michael Echerer <me...@tngtech.com> on 2004/04/13 18:27:12 UTC

Race condition? Visit creation


Hi,

I implemented a service that uses 
Visit visit = (Visit) engine.getVisit(cycle); (engine.getVisit() works aswell)
in its service() method.

This service is wrapped into a component accessing an asset calling this service
to render an image.
In the end I have three img tags with the service urls in one single page.

I put a log statement into my visit constructor. What I saw is that the Visit is
instanciated three! times.

I suppose a race condition because the browser will request the image
simulatiously when loading the page. Thus nearly at the same time the service()
is called. Since the visit wasn't used before it is lazy initialized by Tapestry.

Obviously this isn't synchronized, if I didn't do something wrong... :-(

When I wrap everything in my visit constructor in synchronized(this) the issue
disappears and I get only one constructor log entry.

Question: Do I have to take care myself that the Visit object is garantueed to
be created only once or shouldn't the framework take care of this? Or did I do
anything wrong when attemping to get the visit object in a multithreaded service
without synchronizing myself?

Thx
Michael

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