3

This is regarding Struts1.x

  1. Do Action classes have a scope like form beans do?
  2. Is a new Action instance created for each user session?
  3. If two users use the same action class at a time, will they have two different action class objects, or the same one?

Thanks in advance.

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
user1036204
  • 175
  • 1
  • 2
  • 12

1 Answers1

1

1) The scope on an action decides whether its action form is stored in session- or request-scope. So no, separate from its form bean the action doesn't have a scope.

2) No, Action class instances are created on application start-up and are shared.

3) Requests targeting the same action (meaning they have the same path) will be sent to the same Action object. Being separate method invocations they will get separate copies of variables local to the method, but they will see the same instance variables (with potential for race conditions).

Nathan Hughes
  • 94,330
  • 19
  • 181
  • 276
  • Thanks to Dave Newton and Nathan Hughes, – user1036204 Nov 09 '11 at 02:08
  • Thanks to Dave Newton and Nathan Hughes, (1)Does execute(-,-,-,-) method of Action class is thread safe by default? if we use only the method arguments given by ActionServlet(With a scenario where execute method not using instance variables except the supplied method arguments and not dealing with ant transactional codes)? – user1036204 Nov 09 '11 at 02:26
  • user1036204: an Action is like a Servlet without the boilerplate. "threadsafe" is not the word i'd use. as long as you access only local variables and parameters you're fine. (each method invocation gets its own stackframe so the jvm makes sure those are separate) For instance and class variables, those will be accessed concurrently by multiple threads. i don't know what "ant transactional codes" means. does that help? – Nathan Hughes Nov 09 '11 at 02:37
  • Thank you for quick reply.Sorry i was mentioning about Persistance logic, this would be right word then 'and transactional codes'. – user1036204 Nov 09 '11 at 02:50