473,396 Members | 1,895 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.

Thread-safe static methods/variables

S
Hi there,
I'm building an application that makes heavy use of centralized static
methods (and variables) and would just appreciate hearing someone grade my
understanding of the concept.

In probably common fashion, my static methods are typically in the DAL of my
web application. I don't have any concerns about the methods, but a lot of
collections (ArrayLists, custom collections inheriting from
System.Collections.CollectionBase, etc) are being created and passed out of
this layer. These are _not_ static collections, and my understanding is that
these are instantiated and passed out par norm, regardless of the fact that
the method itself is static. However, knowing that collections are
inherently thread-UNsafe, I still wonder about this and whether there are
exceptions to the rule or pitfalls I should be watching out for. It seems
that I shouldn't be worried about it in the capacity I've just described.
I'm pretty sure this is the case, but I'd rest easier if I could hear an
active confirmation of this..

Thanks for any advice,
S

Nov 18 '05 #1
2 1497
You are ok as long as nothing is shared. The collections you mentioined,
while created/modified in a static method, are in fact created on the heap
as per normal and although the same method can be accessed by multiple users
(static method), the variables it creates are specific heap instances and
therefore not shared across any static methods unless they themselves are
static or thread statics. The DAAB (Data Access Application block) is based
on this premise.

So basically dont worry. All is good.

--
- Paul Glavich
Microsoft MVP - ASP.NET
"S" <st*****@acsalaska.com> wrote in message
news:#e**************@TK2MSFTNGP09.phx.gbl...
Hi there,
I'm building an application that makes heavy use of centralized static
methods (and variables) and would just appreciate hearing someone grade my
understanding of the concept.

In probably common fashion, my static methods are typically in the DAL of my web application. I don't have any concerns about the methods, but a lot of
collections (ArrayLists, custom collections inheriting from
System.Collections.CollectionBase, etc) are being created and passed out of this layer. These are _not_ static collections, and my understanding is that these are instantiated and passed out par norm, regardless of the fact that the method itself is static. However, knowing that collections are
inherently thread-UNsafe, I still wonder about this and whether there are
exceptions to the rule or pitfalls I should be watching out for. It seems
that I shouldn't be worried about it in the capacity I've just described.
I'm pretty sure this is the case, but I'd rest easier if I could hear an
active confirmation of this..

Thanks for any advice,
S

Nov 18 '05 #2
S
Thanks Paul!! I'm restin' easier!

"Paul Glavich [MVP - ASP.NET]" <gl**@aspalliance.com-NOSPAM> wrote in
message news:eV*************@TK2MSFTNGP09.phx.gbl...
You are ok as long as nothing is shared. The collections you mentioined,
while created/modified in a static method, are in fact created on the heap
as per normal and although the same method can be accessed by multiple users (static method), the variables it creates are specific heap instances and
therefore not shared across any static methods unless they themselves are
static or thread statics. The DAAB (Data Access Application block) is based on this premise.

So basically dont worry. All is good.

--
- Paul Glavich
Microsoft MVP - ASP.NET
"S" <st*****@acsalaska.com> wrote in message
news:#e**************@TK2MSFTNGP09.phx.gbl...
Hi there,
I'm building an application that makes heavy use of centralized static
methods (and variables) and would just appreciate hearing someone grade my understanding of the concept.

In probably common fashion, my static methods are typically in the DAL of
my
web application. I don't have any concerns about the methods, but a lot

of collections (ArrayLists, custom collections inheriting from
System.Collections.CollectionBase, etc) are being created and passed out

of
this layer. These are _not_ static collections, and my understanding is

that
these are instantiated and passed out par norm, regardless of the fact

that
the method itself is static. However, knowing that collections are
inherently thread-UNsafe, I still wonder about this and whether there are exceptions to the rule or pitfalls I should be watching out for. It seems that I shouldn't be worried about it in the capacity I've just described. I'm pretty sure this is the case, but I'd rest easier if I could hear an
active confirmation of this..

Thanks for any advice,
S


Nov 18 '05 #3

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

Similar topics

14
by: adeger | last post by:
Having trouble with my first forays into threads. Basically, the threads don't seem to be working in parallel (or you might say are blocking). I've boiled my problems to the following short code...
4
by: Gilles Leblanc | last post by:
Hi I have started a small project with PyOpenGL. I am wondering what are the options for a GUI. So far I checked PyUI but it has some problems with 3d rendering outside the Windows platform. I...
7
by: Ivan | last post by:
Hi I have following problem: I'm creating two threads who are performing some tasks. When one thread finished I would like to restart her again (e.g. new job). Following example demonstrates...
4
by: Matthew Groch | last post by:
Hi all, I've got a server that handles a relatively high number of concurrent transactions (on the magnitude of 1000's per second). Client applications establish socket connections with the...
5
by: Razzie | last post by:
Hi all, A question from someone on a website got me thinking about this, and I wondered if anyone could explain this. A System.Threading.Timer object is garbage collected if it has no...
7
by: Droopy | last post by:
Hi, I don't understand why sometimes, a loop running in a thread takes much more time than usual. I have a thread that must call each 20 ms a C++ unmanaged function. I made a C++ managed...
6
by: Tomaz Koritnik | last post by:
I have a class that runs one of it's method in another thread. I use Thread object to do this and inside ThreadMethod I have an infinite loop: While (true) { // do something Thread.Sleep(100);...
9
by: mareal | last post by:
I have noticed how the thread I created just stops running. I have added several exceptions to the thread System.Threading.SynchronizationLockException System.Threading.ThreadAbortException...
3
by: John Nagle | last post by:
There's no way to set thread priorities within Python, is there? We have some threads that go compute-bound, and would like to reduce their priority slightly so the other operations, like...
34
by: Creativ | last post by:
Why does Thread class not support IDisposable? It's creating quite some problem. Namely, it can exhaust the resource and you have not control over it.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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
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...
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...

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.