|
|
|
start date: Fri, 17 Aug 2007 13:38:18 -0400,
posted on: microsoft.public.dotnet.framework.adonet
back
| Thread Index |
|
1
Max2006 am
|
|
2
(WenYuan Wang [MSFT])
|
|
3
Stephen Howe stephenPOINThoweATtns-globalPOINTcom
|
|
4
(WenYuan Wang [MSFT])
|
Is TableAsapter thread safe?
Hi,
In our ASP.NET application We use strongly typed datasets and TableAdapters.
Is it a good idea to use a static TableAdpater to share the static instance
among all sessions?
My business logic components are like this:
[DataObject]
public static class AccountBLL
{
private static ProfileTableAdapter m_ProfileTableAdapter = null;
private static ProfileTableAdapter AccountProfileTableAdapter
{
get
{
if (m_ProfileTableAdapter == null)
m_ProfileTableAdapter = new ProfileTableAdapter();
return m_ProfileTableAdapter;
}
}
[DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
public static AppDataSet.ProfileDataTable GetAllProfiles()
{
AppDataSet.ProfileDataTable dt;
dt = AccountProfileTableAdapter.GetData();
return dt;
}
}
All asp.net sessions within the web application are going to share a single
instance of ProfileTableAdapter because it is static. I am a bit concern in
high concurrent situations. Is it thread safe?
Any help would be appreciated,
Max
Date:Fri, 17 Aug 2007 13:38:18 -0400
Author:
|
RE: Is TableAsapter thread safe?
Hello Max,
I'm afraid to say TableAdatper is not thread safe.
It is NOT a good idea to share static TableAdatper.
Actually, Table adapter is a DBDATAADAPTER wrapped class which generated by
VS 2005.
For DbDataAdapter, only public STATIC member is thread safe. Any instance
members are not guaranteed to be thread safe.
http://msdn2.microsoft.com/en-us/library/system.data.common.dbdataadapter.as
px
[DbDataAdapter Class].
TableAdatper updates table by calling DbDataAdapter.update() method
directly. Thereby, it is also not guaranteed to be thread safe.
I'd like to suggest creating a new TableAdatper instance for each time you
need it, rather than sharing it among all sessions.
Hope this helps. Please let me know if you have any more concern. We are
glad to assist you.
Have a great day.
Best regards,
Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Date:Mon, 20 Aug 2007 07:30:45 GMT
Author:
|
Re: Is TableAsapter thread safe?
> All asp.net sessions within the web application are going to share a
> single
> instance of ProfileTableAdapter because it is static. I am a bit concern
> in
> high concurrent situations. Is it thread safe?
So what if it is.
You can have 2+ components that are each thread-safe but in combination are
not thread-safe. The thread-safety factor is working at the wrong level.
Each time you move from state-to-state, you want it so that all components
within the state change as one unit, rathe like a database transaction.
Making each component thread-safe does not gurantee that.
Stephen Howe
Date:Mon, 20 Aug 2007 16:10:49 +0100
Author:
|
RE: Is TableAsapter thread safe?
Hello Max,
This is Wen Yuan again. I haven't heard from you a couple of days.
Do you meet any further issue? I just want to check if you have any more
concern.
If so, please feel free to let me know. We are glad to assist you.
Have a great day.
Best regards,
Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Date:Wed, 22 Aug 2007 06:05:50 GMT
Author:
|
|
|