Re: Microsoft Data Access Block and static methods
From: Clint (cjmueller_at_gmail.com)
Date: 12/10/04
- Next message: jaYPee: "Re: ForeignKeyConstraint StudentsSchYrSem requires the child key values (21000013) to exist in the parent table"
- Previous message: Joyjit Mukherjee: "Re: Calling Oracle SPs w/Parameters (PLS-00306)"
- In reply to: Scott Allen: "Re: Microsoft Data Access Block and static methods"
- Next in thread: Scott Allen: "Re: Microsoft Data Access Block and static methods"
- Reply: Scott Allen: "Re: Microsoft Data Access Block and static methods"
- Messages sorted by: [ date ] [ thread ]
Date: 9 Dec 2004 22:37:00 -0800
Thanks, Scott!
The first part of your post did in fact clear up the big hangup I had
w/the MS DAL. I'd just like to try to clarify a few points, though ...
sorry for the constant questions, I just want to make sure I have this
fully understood before I make a big mistake that would cause quite a
lot of problems if data gets mixed up :)
----------
MS assumes the framework is going to be used in a multithreaded
environment and couldn't let static methods not be thread safe.
----------
So I don't have to worry about adding my own lock(...) commands when
referencing MS-written static methods, but if I'm writing my own static
methods that reference static fields in a class, I should use
lock(...)?
ie,
class Foo
{
private static string testValue;
public static void AdjustTestValue()
{
lock (this) // or lock(typeof(Foo))?
{
testValue = "something";
}
}
}
----------
That being said, instance members are not safe because a single
instance of an object is typically not going to be used by multiple
threads. In ASP.NET for instance, you typically create an instance of a
class for each user request - a TextBox control will never see multiple
threads. Since locks add some performance overhead (and a lot of
development and testing overhead), the decision makes a great deal of
sense, even if it looks counterintuitive at first.
----------
I'm having trouble understanding this ... do you mean that in an
ASP.NET (and, for my purpose, Web Services), I should be instantiating
classes instead of using statics, or that it's ok to use statics in
that each request is processed on it's own thread, so long as I don't
actually STORE a value in a static field(ex, inside the static method,
I perform a SQL query only, not storing the result of that query to a
static field)?
Thanks again!
Clint
- Next message: jaYPee: "Re: ForeignKeyConstraint StudentsSchYrSem requires the child key values (21000013) to exist in the parent table"
- Previous message: Joyjit Mukherjee: "Re: Calling Oracle SPs w/Parameters (PLS-00306)"
- In reply to: Scott Allen: "Re: Microsoft Data Access Block and static methods"
- Next in thread: Scott Allen: "Re: Microsoft Data Access Block and static methods"
- Reply: Scott Allen: "Re: Microsoft Data Access Block and static methods"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|