| Author |
Regarding Action Servlet
|
Rohit Dhodapkar
Ranch Hand
Joined: Apr 27, 2006
Posts: 38
|
|
|
Does ActionServlet class in struts single threaded or multithreaded?.
|
 |
Merrill Higginson
Ranch Hand
Joined: Feb 15, 2005
Posts: 4864
|
|
|
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.
|
Merrill
Consultant, Sima Solutions
|
 |
Rohit Dhodapkar
Ranch Hand
Joined: Apr 27, 2006
Posts: 38
|
|
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
Joined: Jun 06, 2006
Posts: 161
|
|
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.
|
Error: Keyboard not attached. Press F1 to continue.
|
 |
Merrill Higginson
Ranch Hand
Joined: Feb 15, 2005
Posts: 4864
|
|
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
Joined: Apr 27, 2006
Posts: 38
|
|
|
Thanks all for the reply
|
 |
 |
|
|
subject: Regarding Action Servlet
|
|
|