473,657 Members | 2,355 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Collecti ons.CollectionB ase, 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 1503
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*****@acsala ska.com> wrote in message
news:#e******** ******@TK2MSFTN GP09.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.Collecti ons.CollectionB ase, 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**@aspallian ce.com-NOSPAM> wrote in
message news:eV******** *****@TK2MSFTNG P09.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*****@acsala ska.com> wrote in message
news:#e******** ******@TK2MSFTN GP09.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.Collecti ons.CollectionB ase, 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
2167
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 block and ensuing output. Seems like the output should be all interleaved and of course it's not. Running Python 2.2 from ActiveState on Windows XP (also doesn't work on Windows 2000). Thanks in advance! adeger
4
2885
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 know of WxPython but I don't know if I can create a WxPython window, use gl rendering code in it and then put widgets on top of that...
7
2700
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 that. Problem is that when program is started many threads are created (see output section), when only two should be running at any time. Can you please help me to identify me where the problem is? Best regards
4
5428
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 server. Data is sent and received over these connections using the asynchronous model. The server is currently in beta testing. Sporadically over the course of the day, I'll observe the thread count on the process (via perfmon) start climbing....
5
2823
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 references to it. But what about threads? If I start a new thread that only does 1+1, is it garbage collected after that? If so, do all threads get garbage collected eventually that are 'done'? And if not, why not? Are there references to the thread that...
7
2762
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 wrapper for calling this function from C# (see below _serialChannel.ItTask ()). It works great but for this timing problem. Here below, the main loop for this thread :
6
23729
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); } The problem is that I don't know how to terminate the thread when my class
9
3068
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 System.Threading.ThreadInterruptedException System.Threading.ThreadStateException to see if I could get more information about why the thread stops running but that code is never executed. Any ideas on how I can debug this?
3
35168
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 accessing the database and servicing queries, aren't slowed as much. John Nagle
34
2778
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
8399
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8312
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8732
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8504
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8606
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7337
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6169
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
1959
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.