Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

static methods  RSS feed

 
lekha phijo
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a static method used to retrive data from databases.
What problem could I face if there are concurrent users accessing the same method.
Please suggest performance issues related to static methods.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would only face problems with concurrent users IF the static method made use of static variables to hold user-specific objects such as a database connection. If all variables are either on the stack or held in user specific object instances, no problem will arise.
I know of no performance issues related to static methods - you should be worried about clarity of design, not minute differences in execution speed.
Bill
 
lekha phijo
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank u bill.
Thats right I guess I should concentrate on the code pattern.
 
Rajeev Gupta
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI Bill
Is it not true that at any given point of time, only one user can execute this method. Hence if there are maney concurrent users then all such calls would be queued and they would be executed serailly. is it not a performance issue?
Regards
Rajeev
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it not true that at any given point of time, only one user can execute this method.

You appear to be thinking about synchronized methods - a static method can be synchronized or not depending on the requirements.
If the static method has to use a static variable - such as a database connection - then of course you would have to synchronize access to it.
On the other hand, if each Thread calling the static method had its own database connection instance, there would be no problem.
Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!