473,498 Members | 1,648 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Static methods

Hi all,

I'm considering using a the micorsoft data access block as the main DAC for
my application. A colleage of mine suggested that I might have a problem
with concurrency though

When a method is static, do I need to worry about concurrency?

I figured that microsoft would have had this in mind when making the
component. Obviously numerous users are going to be routing calls through
this component at the same time.

Should I be worried about this and what can I do if it is going to be a
problem? The system will sustain about 200 users at any one time

Thanks for your help

Simon
Jul 21 '05 #1
4 1614
Simon Harvey <si**********@the-web-works.co.uk> wrote:
I'm considering using a the micorsoft data access block as the main DAC for
my application. A colleage of mine suggested that I might have a problem
with concurrency though

When a method is static, do I need to worry about concurrency?


Absolutely. There could be more than one thread accessing the static
method at a time. That doesn't mean you can't make it thread-safe, but
it's not going to be automatically thread-safe just by being static.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2
Hi Jon,

What would the simplest and most effective mechanism for making the method
thread safe?

Thanks for your help

Simon
Jul 21 '05 #3
Simon Harvey <si**********@the-web-works.co.uk> wrote:
What would the simplest and most effective mechanism for making the method
thread safe?


Learning about thread-safety in general, and applying those principles
:)

It all depends on what the method is doing.

See http://www.pobox.com/~skeet/csharp/multithreading.html for more
information.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #4
"Simon Harvey" <si**********@the-web-works.co.uk> wrote in
news:OY**************@tk2msftngp13.phx.gbl:
Hi all,

I'm considering using a the micorsoft data access block as the main
DAC for my application. A colleage of mine suggested that I might have
a problem with concurrency though

When a method is static, do I need to worry about concurrency?


Any method that does not handle any data external to the method is by
default thread safe, or at least as thread-safe as the parameters to it
are.

As such, a static method that only operates on the parameters it's given,
and those parameters are also thread-safe in the sense that no other
thread is operating on them at the same time, then that method will be
thread safe. Additionally, any local variables held in the class must
also be thread safe in the sense that they must not be depending on other
instances of objects than themselves. For instance, if you create a new
object inside the method, that's ok. If that object adds itself to a
static/shared list somewhere, that code must be thread-safe or you will
have a problem.

If the method (static or not) operates on anything outside of this, like
member variables (static or not), external system resources (files,
serial ports, etc.), then that method must be written specifically with
thread safety in mind.

--
Lasse Vågsæther Karlsen
la***@vkarlsen.no
PGP KeyID: 0x0270466B
Jul 21 '05 #5

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

Similar topics

13
10669
by: Axehelm | last post by:
Okay, I'm in a debate over whether or not static methods are a good idea in a general domain class. I'm personally not a fan of static methods but we seem to be using them to load an object. ...
4
7993
by: Neil Zanella | last post by:
Hello, I would like to know whether it is possible to define static class methods and data members in Python (similar to the way it can be done in C++ or Java). These do not seem to be mentioned...
3
1979
by: Steven D'Aprano | last post by:
I've been doing a lot of reading about static methods in Python, and I'm not exactly sure what they are useful for or why they were introduced. Here is a typical description of them, this one...
1
2182
by: baylor | last post by:
In C#, an interface cannot mark any method as static. i'm told the ILASM supports it but i've never tested that Two questions. First, why? OK, i've heard the reason about interfaces being...
8
52739
by: Steven Livingstone | last post by:
Anyone able to explain to me why you cannot define an interface that can then be implemented using static methods? I understand the C# CLS states this, but just interested in the reasons behind...
3
9725
by: Mauzi | last post by:
hi, this may sound odd and noob like, but what is the 'big' difference between static and non-static funcitons ? is there any performace differnce? what is the best way to use them ? thnx ...
3
2088
by: Jay | last post by:
Why are there static methods in C#. In C++ static was applied to data only (I believe) and it meant that the static piece of data was not a part of the object but only a part of the class (one...
8
2043
by: Fernando Lopes | last post by:
Hi there! Someone has some code sample about when is recommend use a statis method? I know this methos don't want to be initialized and all but I want to know when I need to use it. Tks....
12
3546
by: chandu | last post by:
hello, i want to know usage of static methods in a class. is it advantageous or disadvantage to use more static methods in a class. thank u
9
5829
by: Steve Richter | last post by:
in a generic class, can I code the class so that I can call a static method of the generic class T? In the ConvertFrom method of the generic TypeConvert class I want to write, I have a call to...
0
7126
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
7005
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7168
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
7210
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6891
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
7381
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
5465
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,...
1
4916
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
1
659
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.