• Post Reply Bookmark Topic Watch Topic
  • New Topic

static methods in web development?  RSS feed

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am doing web development using Weblogic and Struts, using .jsp's, Action classes etc. (typical web development project). Also, I have a Util's class that has a lot of static methods in it that does a lot of fix ups, etc. in it. And I call these methods a lot from my .jsp's and Actions classes. My question is - is this bad practice? - i.e. possible threading, syncronization problems with this? If so, what is a good alternative - would making the Utils class a Singleton be an improvement, or just make the Utils class a regular class - having to instatiate the object and then call the appropriate method or what?

Many Thanks
 
Bartender
Posts: 9443
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a common practice. You will not have problems with multiple threads if you declare all your variables except finals within your methods. As for an alternative, creating a singleton and synchronizing access to it would be a bottleneck as only one thread would have access at a time. Instantiating a class would be more work than necessary unless you need individual instances to represent data or state between calls.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!