• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Action class in Struts

 
Ranch Hand
Posts: 367
Eclipse IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I'm working on Struts.
I went through the existing code written by my team and they have written many static methods in the action class.
So is it a right thing to mention such things in the action class apart from 'execute()' method, also the execute method is also containing business logic.
Also, should an action class have only one method i.e. execute ? not even a static block ?

The code is working fine. But is it a right design approach ?

Please advise.
 
Ranch Hand
Posts: 349
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What are those action methods doing? Are they doing something with the state of the request. If so it is a bad design.
In my humble opinion having static methods in action is not a good design.

Let us see what others think.
 
pramod talekar
Ranch Hand
Posts: 367
Eclipse IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ananth.
I'd like to hear more reviews/suggestions.
 
Ranch Hand
Posts: 485
Eclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Struts 1 or struts 2
 
pramod talekar
Ranch Hand
Posts: 367
Eclipse IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Struts 1.2
 
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On average, how many human users does the application support? How many concurrent users are there at peak load time?
 
pramod talekar
Ranch Hand
Posts: 367
Eclipse IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jimmy,
The app is meant for at least 25k+ users.
There are around 5k users at a time using that app.
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you say "meant for", does these mean that the application is not in Production or has never been completed?

Has the application ever supported 25K users?

Has the application ever supported 5K concurrent users?
 
pramod talekar
Ranch Hand
Posts: 367
Eclipse IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jimmy,

The application is meant for all employees of a huge company which has more than 50k users.
And we never checked how many concurrent users are supported as there is no limitation to that.

I'm using java in a tool which is used in "Identity and access management".
and the java code uses struts 1.2 framework.

 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are employees using the application today? If so, are there any problems?
 
pramod talekar
Ranch Hand
Posts: 367
Eclipse IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jimmy,

Yes, the employees of a particular team do use that app and it will be extended to other depts soon.
There is no problem with the code during runtime.

I'm just asking from the design perspective.
Is it a proper design to have different static methods and a static block apart from the execute method in the action class in struts 1.2
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you wanted to switch over to using a different GUI, say a desktop application, how long would it take to get this working? What would your estimate be?
 
pramod talekar
Ranch Hand
Posts: 367
Eclipse IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The app has over 20 jsp and few other complex things making use of eDirectory. I think 4 weeks should be fine.
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In order to support both the HTML GUI and the desktop GUI, would you have two copies of business logic, one for HTML and the other for desktop?
 
pramod talekar
Ranch Hand
Posts: 367
Eclipse IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think so.
Could you please tell me the point you want to make?
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you wouldn't have two copies of business logic, are you saying that you would build the desktop GUI to use the Struts Action classes?
 
pramod talekar
Ranch Hand
Posts: 367
Eclipse IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have never used struts for desktop gui, so don't have any clue.
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On another note, are you able to test out business logic from a command-line using a simple Java class with a main method?

Or, when testing business logic, do you always have to have a web server running and need to use the application's HTML pages?
 
pramod talekar
Ranch Hand
Posts: 367
Eclipse IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Jimmy,
Can you ask all questions at a time?
So that I can talk to my team mates and tell you.
 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

pramod talekar wrote:Hello,

I'm working on Struts.
I went through the existing code written by my team and they have written many static methods in the action class.
So is it a right thing to mention such things in the action class apart from 'execute()' method, also the execute method is also containing business logic.
Also, should an action class have only one method i.e. execute ? not even a static block ?

The code is working fine. But is it a right design approach ?

Please advise.



When people go on coding for long time without paying attention features like re-usability, testability, scalability start getting compromised. Programmers focus on pushing the next feature/fix out of the door and management has no problem in that. Most of the projects go in this direction, nobody else is to blame but the work environment and human nature.

In general, no static methods should be there in Struts 2 Action classes. Most of the times, all you need are execute() method and setters/getters for domain objects or data to expose/receive. If code contains static methods or static variables in a Struts 2 action, something is wrong and same should be do-able using method parameters.

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Threading Model
Struts 1 Actions are singletons therefore they must be thread-safe because only one instance of a class handles all the requests for that Action. The singleton strategy restricts to Struts 1 Actions and requires extra care to make the action resources thread safe or synchronized while developing an application.

Struts 2 doesn't have thread-safety issues as Action objects are instantiated for each request. A servlet container generates many throw-away objects per request, and one more object does not impose a performance penalty or impact garbage collection.



and your question is about the struts 1.2
i feel using static methods will work fine
STATIC METHOD IS LIKE A METHOD WHICH IS NOT DEPENDENT ON THE INSTANCE VARIABLES IN THE CLASS
SO WE CAN PUT SOME GENERIC FUNCTIONALITY IN THAT METHOD RELATED TO THAT CLASS

I think those methods might be used by the some other classes so they are marked as static

hope this helps
 
pramod talekar
Ranch Hand
Posts: 367
Eclipse IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well said Varun

And thanks Ravindra for sharing your view.

cheers.
 
The knights of nee want a shrubbery. And a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic