You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Handy, Steve" <St...@ps.net> on 2001/04/02 21:32:26 UTC

Thread safety issue with use of token?

Previous posts have referred to using the token methods of Action to detect
duplicate requests (from the user clicking more than once without waiting
for a new page).  For an example, see
http://www.mail-archive.com/struts-user@jakarta.apache.org/msg02368.html.

Are there thread safety issues with this?

The description says to put this at the bottom of the action that leads to
the page being displayed:

saveToken(request);

And, put this near the top of the action that handles the page submission:

if (!isTokenValid(request)) {
  ... deal with the error ...
}
resetToken(request);

Should this latter section be synchronized so that two racing threads from
two nearly simultaneous submits from the same user don't both get past the
test before the token is reset?

Help me understand.  Am I ...
- overly anal, since such a race is practically impossible?
or
- unaware of thread-simplification qualities of Struts?
or
- under-educated about how the Struts token capability handles this for us?

Thanks,

Steve

Re: Thread safety issue with use of token?

Posted by Rob Leland <Ro...@freetocreate.org>.
If you are using multiple threads per session you'll need
to find another method for transaction control.

Specifically in the session you'll need to create
a Map of tokens, and use the request id as a lookup key.


-Rob






"Handy, Steve" wrote:
> 
> Previous posts have referred to using the token methods of Action to detect
> duplicate requests (from the user clicking more than once without waiting
> for a new page).  For an example, see
> http://www.mail-archive.com/struts-user@jakarta.apache.org/msg02368.html.
> 
> Are there thread safety issues with this?
> 
> The description says to put this at the bottom of the action that leads to
> the page being displayed:
> 
> saveToken(request);
> 
> And, put this near the top of the action that handles the page submission:
> 
> if (!isTokenValid(request)) {
>   ... deal with the error ...
> }
> resetToken(request);
> 
> Should this latter section be synchronized so that two racing threads from
> two nearly simultaneous submits from the same user don't both get past the
> test before the token is reset?
> 
> Help me understand.  Am I ...
> - overly anal, since such a race is practically impossible?
> or
> - unaware of thread-simplification qualities of Struts?
> or
> - under-educated about how the Struts token capability handles this for us?
> 
> Thanks,
> 
> Steve