Thread-safe static methods/variables

  • Thread starter Thread starter S
  • Start date Start date
S

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
 
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.
 
Back
Top