Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Using Statis methods in a Web Based Application  RSS feed

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

Is it ever feasable to use static methods in a web based application ?
(as they will be one per class )

so any operation done by one Thread will effect other requests also know .
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course it is feasible, I do it all the time. The usual precautions for multi-threaded applications apply.

Bill
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thanks William . just recently saw a Template of an Application for getting SessionFactory in Hibernate .




Now my query is that why do people prefer static methods in this situations ??

 
Himanshu Kansal
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is done to make sure that only 1 instance of a class is used throughout the application for various reasone like consistency, cost effectiveness etc.

Eg: In the Hibernate example quoted by you, the application need not start a new session for each db request, it can do away with making requests by getting sessions from the same factory instead
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!