Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Calling Helper class static methods from Struts action class.

 
Ramu Valivarthi
Ranch Hand
Posts: 37
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Iam calling a Helper class with all static methods from struts action class. My question is, if multiple requests are coming to action , the static methods in Helper holds other request's data.so is it correct to using static methods across multiple requests.
 
Niiraj Patel
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ramu,

You can use static methods when you want to use it as utility method.

In short, Don't assign/change value of any static class variables to make it thread safe.

Your static methods would be safe.
--Niraj
 
Ramu Valivarthi
Ranch Hand
Posts: 37
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Niraj Thanks for prompt response,

In my case the data will get changed for each request ,the flow is something like Action <--> Helper (static) <--> ServiceImpl <--> MilldeTier (Jboss EJB)<--> DAO
I just wanted to know , whether static methods will cause any issue ?
 
Niiraj Patel
Ranch Hand
Posts: 47
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
howdly ramu,
please have a look at this thread ..
http://stackoverflow.com/questions/5173399/are-non-synchronised-static-methods-thread-safe-if-they-dont-modify-static-class

Thanks,
niraj
 
Ramu Valivarthi
Ranch Hand
Posts: 37
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Niraj
Its cleared..Iam safe now as my static methods are thread safe.



Ramu V.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic