This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding Action Servlet

 
Rohit Dhodapkar
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does ActionServlet class in struts single threaded or multithreaded?.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is multithreaded, which means it must be coded as thread-safe. This means don't use instance variables unless you intend for them to be shared by all users of the application.
 
Rohit Dhodapkar
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all thanks for the reply ..So does that mean than any instance variable in the action class is shared my multiple user .
If yes how can I avoid this situation .. My code has a requirement to keep instance varialbe which should be specific to a user ..How should I deal with itt..
 
Travis Hein
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the instance variable is local to the action form, you may store it as a property in the actionForm bean. when the action form is mapped as session scope (default), it is stored as a session attribute and implicity loaded by struts when the action is used. Note that while the action handler needs to be thread safe, the actionForm bean is a bean.

another alternative if the data you want to store for a user is not specific to a screen or an action, you can store it into a normal session attribute.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anyone who is making instance variables in Action classes a "requirement" is asking for an application that doesn't work -- or even worse -- sometimes works and sometimes doesn't. If you need data for a single user to psersist between requests, put that data in the user's HTTPSession. For example:

String myData = "hello world";
request.getSession.setAttribute("myData", myData);

Then, in the next request, you can retrieve it with:

String myData = (String) request.getSession().getAttribute("myData");
 
Rohit Dhodapkar
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all for the reply
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic