473,396 Members | 1,789 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Question on use of Static Methods

In another post Kevin Spencer stated: "one should be careful of using static
fields, properties, and methods, by understanding what the implications of
such are (e.g. locking static variables when changing because they are not
thread-safe)."

Can someone please elaborate on the pros and cons of using static methods?
(In VB they are called Shared methods.) The MS DAAB uses Shared methods.
This means that all Data Access calls go through this block of code without
instantiating an instance. I assumed that this would be a highly scalable
solution. Is this assumption correct? Or are there drawbacks to using shared
methods that reduce the scalability? Do multiple users ever "step on each
other"? For example, can UserA end up with UserB's Datareader?

Appreciate any advice.
--
Joe Fallon

Nov 18 '05 #1
4 2018
"Joe Fallon" <jf******@nospamtwcny.rr.com> wrote in message
news:u3*************@TK2MSFTNGP10.phx.gbl...
In another post Kevin Spencer stated: "one should be careful of using static fields, properties, and methods, by understanding what the implications of
such are (e.g. locking static variables when changing because they are not
thread-safe)."

Can someone please elaborate on the pros and cons of using static methods?
(In VB they are called Shared methods.) The MS DAAB uses Shared methods.
This means that all Data Access calls go through this block of code without instantiating an instance. I assumed that this would be a highly scalable
solution. Is this assumption correct? Or are there drawbacks to using shared methods that reduce the scalability? Do multiple users ever "step on each
other"? For example, can UserA end up with UserB's Datareader?


Shared fields or properties are shared by all users. That's the big problem.

I don't know of a problem with accessing Shared methods which do not refer
to Shared data.
--
John Saunders
johnwsaundersiii at hotmail
Nov 18 '05 #2
Generally static methods should never be a problem. Statics are nice
precisely because you don't need and instance ref first, although I suspect
that the overhead of creating an instance would be minimal in the first
place. More than anything it's about the convenience of having those methods
available directly without setting up an instance. If your methods don't
require class level data and they're self contained they're good canidates
for static methods.

it's static data you have to be potentially aware of for potential
multi-threading lock issues as any data that is static is shared by the
entire ASP.Net application and its AppDomain. I use static data quite a bit
in my apps for storing configuration data and a number of one time loaded
references to reused data of all sorts. If data is read only or only updated
under very controlled circumstances statics can be very efficient as it's
simply a direct reference. With read-only scenarios there's little to worry
about although you still have to be aware that some objects of the framework
itself may use internal data to manage their state which can cause odd
behavior when multiple threads access these objects. Remember that ASP.Net
handles each incoming request on a separate thread and each of those threads
shares the same property data.
+++ Rick ----

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
----------------------------------
Making waves on the Web
"Joe Fallon" <jf******@nospamtwcny.rr.com> wrote in message
news:u3*************@TK2MSFTNGP10.phx.gbl...
In another post Kevin Spencer stated: "one should be careful of using static fields, properties, and methods, by understanding what the implications of
such are (e.g. locking static variables when changing because they are not
thread-safe)."

Can someone please elaborate on the pros and cons of using static methods?
(In VB they are called Shared methods.) The MS DAAB uses Shared methods.
This means that all Data Access calls go through this block of code without instantiating an instance. I assumed that this would be a highly scalable
solution. Is this assumption correct? Or are there drawbacks to using shared methods that reduce the scalability? Do multiple users ever "step on each
other"? For example, can UserA end up with UserB's Datareader?

Appreciate any advice.
--
Joe Fallon


Nov 18 '05 #3
Generally static methods should never be a problem. Statics are nice
precisely because you don't need and instance ref first, although I suspect
that the overhead of creating an instance would be minimal in the first
place. More than anything it's about the convenience of having those methods
available directly without setting up an instance. If your methods don't
require class level data and they're self contained they're good canidates
for static methods.

it's static data you have to be potentially aware of for potential
multi-threading lock issues as any data that is static is shared by the
entire ASP.Net application and its AppDomain. I use static data quite a bit
in my apps for storing configuration data and a number of one time loaded
references to reused data of all sorts. If data is read only or only updated
under very controlled circumstances statics can be very efficient as it's
simply a direct reference. With read-only scenarios there's little to worry
about although you still have to be aware that some objects of the framework
itself may use internal data to manage their state which can cause odd
behavior when multiple threads access these objects. Remember that ASP.Net
handles each incoming request on a separate thread and each of those threads
shares the same property data.
+++ Rick ----

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
----------------------------------
Making waves on the Web
"Joe Fallon" <jf******@nospamtwcny.rr.com> wrote in message
news:u3*************@TK2MSFTNGP10.phx.gbl...
In another post Kevin Spencer stated: "one should be careful of using static fields, properties, and methods, by understanding what the implications of
such are (e.g. locking static variables when changing because they are not
thread-safe)."

Can someone please elaborate on the pros and cons of using static methods?
(In VB they are called Shared methods.) The MS DAAB uses Shared methods.
This means that all Data Access calls go through this block of code without instantiating an instance. I assumed that this would be a highly scalable
solution. Is this assumption correct? Or are there drawbacks to using shared methods that reduce the scalability? Do multiple users ever "step on each
other"? For example, can UserA end up with UserB's Datareader?

Appreciate any advice.
--
Joe Fallon


Nov 18 '05 #4
Rick,
Thanks for the comments.
Just what I was hoping to hear.
--
Joe Fallon

"Rick Strahl [MVP]" <ri********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Generally static methods should never be a problem. Statics are nice
precisely because you don't need and instance ref first, although I suspect that the overhead of creating an instance would be minimal in the first
place. More than anything it's about the convenience of having those methods available directly without setting up an instance. If your methods don't
require class level data and they're self contained they're good canidates
for static methods.

it's static data you have to be potentially aware of for potential
multi-threading lock issues as any data that is static is shared by the
entire ASP.Net application and its AppDomain. I use static data quite a bit in my apps for storing configuration data and a number of one time loaded
references to reused data of all sorts. If data is read only or only updated under very controlled circumstances statics can be very efficient as it's
simply a direct reference. With read-only scenarios there's little to worry about although you still have to be aware that some objects of the framework itself may use internal data to manage their state which can cause odd
behavior when multiple threads access these objects. Remember that ASP.Net
handles each incoming request on a separate thread and each of those threads shares the same property data.
+++ Rick ----

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
----------------------------------
Making waves on the Web
"Joe Fallon" <jf******@nospamtwcny.rr.com> wrote in message
news:u3*************@TK2MSFTNGP10.phx.gbl...
In another post Kevin Spencer stated: "one should be careful of using

static
fields, properties, and methods, by understanding what the implications of such are (e.g. locking static variables when changing because they are not thread-safe)."

Can someone please elaborate on the pros and cons of using static methods? (In VB they are called Shared methods.) The MS DAAB uses Shared methods.
This means that all Data Access calls go through this block of code

without
instantiating an instance. I assumed that this would be a highly scalable solution. Is this assumption correct? Or are there drawbacks to using

shared
methods that reduce the scalability? Do multiple users ever "step on each other"? For example, can UserA end up with UserB's Datareader?

Appreciate any advice.
--
Joe Fallon



Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Tom Dacon | last post by:
I'm curious to see if anyone has an opinion on this little design question - I'm doing a computational astronomy library in C#, purely for my own use, and one of the things that happens regularly...
5
by: allison | last post by:
Can someone point me to a guide on when to use static methods versus instance methods in a class? For instance, is it bad design to have a static method that creates an instance of another class? ...
3
by: Amadelle | last post by:
Hi All and thanks in advance, I wanted to know when is a good idea to use a static class (with static constructor) and when to use instance classes? I have read couple of articles on line and...
44
by: craig | last post by:
I am wondering if there are some best practices for determining a strategy for using try/catch blocks within an application. My current thoughts are: 1. The code the initiates any high-level...
11
by: dhnriverside | last post by:
Hi peeps Ok, so I thought I'd have a go at making a console app in VS2k5... I haven't written any windows apps for years, let alone dos apps (been web programming) and I've hit a dumb error... ...
6
by: Simon Harvey | last post by:
Hi all, In my project I have made a number of helper methods static. As I understand it, this will create the problem that multiple threads could access the static method at the same time and...
5
by: wrecker | last post by:
Hi all, I have a few common methods that I need to use at different points in my web application. I'm wondering where the best place would be to put these? I think that I have three options. ...
15
by: dn | last post by:
I'm starting an n-tier application with an ASP.NET 2.0 presentation layer, a business layer, a data access layer, and a SQL Server 2005 database, and I have a question. In the business and data...
18
by: Tom Cole | last post by:
I'm working on a small Ajax request library to simplify some tasks that I will be taking on shortly. For the most part everything works fine, however I seem to have some issues when running two...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.