Hi everybody,
I am new to ASP.NET, and my question might be obvious to most of you but I
do not seem to find many things about threads and ASP.NET.
I have an object(Object 1) which need some service from another
object(Object2).
Object 2 has only two methods and no members.
Load(Object1 obj, int id);
Save(Object1 obj);
I will have thousands instances from Object1, but to save memory I will only
have one instance of Object2.
I decided to create only one reference of Object2 and keep it as class
member of Object1 class.
Now if I have only one instance per class, any user logged to the
application (any session) will use the same Object2 obj2 reference.
My question is: Should I make Load() and Save() methods of Object2 thread
safe(Using Lock for example), or ASP.NET will take care of different
sessions(users) accessing this methods.
Again I do not create separate threads. I just wonder if ASP.NET make a
separate thread for any of application users (any session) or it creates a
separate process(with separate allocated memory ) per session and this
process memory area is guarded from other processes.
Thanks 8 1341
You get the wrong concept this is asp.net not windowsform.
chanmm
"Angel" <an*****@hotmail.com> wrote in message
news:uO**************@TK2MSFTNGP12.phx.gbl... Hi everybody, I am new to ASP.NET, and my question might be obvious to most of you but I do not seem to find many things about threads and ASP.NET.
I have an object(Object 1) which need some service from another object(Object2). Object 2 has only two methods and no members.
Load(Object1 obj, int id); Save(Object1 obj);
I will have thousands instances from Object1, but to save memory I will
only have one instance of Object2. I decided to create only one reference of Object2 and keep it as class member of Object1 class.
Now if I have only one instance per class, any user logged to the application (any session) will use the same Object2 obj2 reference. My question is: Should I make Load() and Save() methods of Object2 thread safe(Using Lock for example), or ASP.NET will take care of different sessions(users) accessing this methods.
Again I do not create separate threads. I just wonder if ASP.NET make a separate thread for any of application users (any session) or it creates
a separate process(with separate allocated memory ) per session and this process memory area is guarded from other processes.
Thanks
I presume you are using a singleton pattern, I always lock when writing and
depending on the object type lock when reading aswell.
remember, ASP.NET is stateless, yes you can create a object that sits around
but ASP.NET could kill it when it gets recycled and you don't get any
warning of this, so if you are saving things in memory that you need to keep
then watch out.
Steve
"Angel" <an*****@hotmail.com> wrote in message
news:uO**************@TK2MSFTNGP12.phx.gbl... Hi everybody, I am new to ASP.NET, and my question might be obvious to most of you but I do not seem to find many things about threads and ASP.NET.
I have an object(Object 1) which need some service from another object(Object2). Object 2 has only two methods and no members.
Load(Object1 obj, int id); Save(Object1 obj);
I will have thousands instances from Object1, but to save memory I will
only have one instance of Object2. I decided to create only one reference of Object2 and keep it as class member of Object1 class.
Now if I have only one instance per class, any user logged to the application (any session) will use the same Object2 obj2 reference. My question is: Should I make Load() and Save() methods of Object2 thread safe(Using Lock for example), or ASP.NET will take care of different sessions(users) accessing this methods.
Again I do not create separate threads. I just wonder if ASP.NET make a separate thread for any of application users (any session) or it creates
a separate process(with separate allocated memory ) per session and this process memory area is guarded from other processes.
Thanks
Thanks Steve,
You got it right. I use something as singleton. I have one object per
class.
Let say my user is Student
When user login I create a UserObject that I save in Session["User"].
Then on demand I fill its collection properties student classes ,
teachers.... Any of those collections have a class reference to a
DataPersistObject instance.
Every class of those collection properties has a class reference to an
object (DataPersistObject ) which has only 2 methods
Load(obj, id) and Save(obj), they retrieve or save one object per time from
a database to collection and vice versa.
The problem is that I do not know how different sessions will interact
(behave) when accessing the methods of this object.
Should I synchronize "Load" and "Save" methods using "lock(this)" within
the methods body , or ASP.Net will take care of this concurrent access to
this methods between different sessions.
When the user logout all this will be released since the only place keeping
reference to this properties is UserObject, which is released when
session["User is released"].
My guess is that class references to my DataPersist object would not be
released until Application is running, because they have been created with
Static constructor like this:
static Teachers()
{
//fdmobj is defined in the base class
fdmobj = new DMTeacher();
}
Angel
"Steve Drake" <Steve@_NOSPAM_.Drakey.co.uk> wrote in message
news:u$*************@TK2MSFTNGP09.phx.gbl... I presume you are using a singleton pattern, I always lock when writing
and depending on the object type lock when reading aswell.
remember, ASP.NET is stateless, yes you can create a object that sits
around but ASP.NET could kill it when it gets recycled and you don't get any warning of this, so if you are saving things in memory that you need to
keep then watch out.
Steve
"Angel" <an*****@hotmail.com> wrote in message news:uO**************@TK2MSFTNGP12.phx.gbl... Hi everybody, I am new to ASP.NET, and my question might be obvious to most of you but
I do not seem to find many things about threads and ASP.NET.
I have an object(Object 1) which need some service from another object(Object2). Object 2 has only two methods and no members.
Load(Object1 obj, int id); Save(Object1 obj);
I will have thousands instances from Object1, but to save memory I will only have one instance of Object2. I decided to create only one reference of Object2 and keep it as class member of Object1 class.
Now if I have only one instance per class, any user logged to the application (any session) will use the same Object2 obj2 reference. My question is: Should I make Load() and Save() methods of Object2
thread safe(Using Lock for example), or ASP.NET will take care of different sessions(users) accessing this methods.
Again I do not create separate threads. I just wonder if ASP.NET make a separate thread for any of application users (any session) or it
creates a separate process(with separate allocated memory ) per session and this process memory area is guarded from other processes.
Thanks
Hi Angel:
If the Load and Save methods are stateless, then you don't need to
worry about locking. A stateless method will use only local variables
and parameters to the method. You should consider making the methods
static, then all of your object1 instances won't even need to store a
reference to object2.
You are correct in thinking ASP.NET will use multiple threads to
service incoming requests. It won't prevent thread unsafe code from
bad bahvior.
--
Scott http://www.OdeToCode.com
On Tue, 10 Aug 2004 10:48:46 -0400, "Angel" <an*****@hotmail.com>
wrote: Hi everybody, I am new to ASP.NET, and my question might be obvious to most of you but I do not seem to find many things about threads and ASP.NET.
I have an object(Object 1) which need some service from another object(Object2). Object 2 has only two methods and no members.
Load(Object1 obj, int id); Save(Object1 obj);
I will have thousands instances from Object1, but to save memory I will only have one instance of Object2. I decided to create only one reference of Object2 and keep it as class member of Object1 class.
Now if I have only one instance per class, any user logged to the application (any session) will use the same Object2 obj2 reference. My question is: Should I make Load() and Save() methods of Object2 thread safe(Using Lock for example), or ASP.NET will take care of different sessions(users) accessing this methods.
Again I do not create separate threads. I just wonder if ASP.NET make a separate thread for any of application users (any session) or it creates a separate process(with separate allocated memory ) per session and this process memory area is guarded from other processes.
Thanks
I was thinking of doing this methods static and now when you mentioned it I
think that this is better idea anyway.
I did not made them static originally because I've had an idea to keep some
values there.
Later I realized that this will give me only troubles and give it up.
Thanks
Angel
Yeah...
With the archetecture of ASP.NET, I imagine that the only way to
preserve an object across many sessions is by creating an actual windows
service that preserves the state of the object. If this were the case,
then you would just have a queue of items waiting on this service, which
would negate any cross-access issues. Of course, it's probably way
easier to just use static functions, like stated somewhere else in this
thread.
Mike
Angel wrote: Thanks Steve, You got it right. I use something as singleton. I have one object per class. Let say my user is Student When user login I create a UserObject that I save in Session["User"]. Then on demand I fill its collection properties student classes , teachers.... Any of those collections have a class reference to a DataPersistObject instance. Every class of those collection properties has a class reference to an object (DataPersistObject ) which has only 2 methods Load(obj, id) and Save(obj), they retrieve or save one object per time from a database to collection and vice versa. The problem is that I do not know how different sessions will interact (behave) when accessing the methods of this object. Should I synchronize "Load" and "Save" methods using "lock(this)" within the methods body , or ASP.Net will take care of this concurrent access to this methods between different sessions.
When the user logout all this will be released since the only place keeping reference to this properties is UserObject, which is released when session["User is released"].
My guess is that class references to my DataPersist object would not be released until Application is running, because they have been created with Static constructor like this:
static Teachers() { //fdmobj is defined in the base class fdmobj = new DMTeacher();
}
Angel
"Steve Drake" <Steve@_NOSPAM_.Drakey.co.uk> wrote in message news:u$*************@TK2MSFTNGP09.phx.gbl...
I presume you are using a singleton pattern, I always lock when writing
and
depending on the object type lock when reading aswell.
remember, ASP.NET is stateless, yes you can create a object that sits
around
but ASP.NET could kill it when it gets recycled and you don't get any warning of this, so if you are saving things in memory that you need to
keep
then watch out.
Steve
"Angel" <an*****@hotmail.com> wrote in message news:uO**************@TK2MSFTNGP12.phx.gbl...
Hi everybody, I am new to ASP.NET, and my question might be obvious to most of you but I do not seem to find many things about threads and ASP.NET.
I have an object(Object 1) which need some service from another object(Object2). Object 2 has only two methods and no members.
Load(Object1 obj, int id); Save(Object1 obj);
I will have thousands instances from Object1, but to save memory I will
only
have one instance of Object2. I decided to create only one reference of Object2 and keep it as class member of Object1 class.
Now if I have only one instance per class, any user logged to the application (any session) will use the same Object2 obj2 reference. My question is: Should I make Load() and Save() methods of Object2 thread safe(Using Lock for example), or ASP.NET will take care of different sessions(users) accessing this methods.
Again I do not create separate threads. I just wonder if ASP.NET make a separate thread for any of application users (any session) or it
creates
a
separate process(with separate allocated memory ) per session and this process memory area is guarded from other processes.
Thanks
> Of course, it's probably way easier to just use static functions, like stated somewhere else in this thread.
True, except if one tries to utilize objects polymorphic behavior.
Static methods cannot be virtual.
> With the archetecture of ASP.NET, I imagine that the only way to preserve an object across many sessions is by creating an actual windows service that preserves the state of the object.
no, it's not the only way. and your approach isn't recommended either since
a windows service is not guaranteed to be running when your application
runs. the cache object shares state across sessions, also the static
modifier implements one copy per appdomain which is shared across sessions.
--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
"Mike Newton" <MN*****@discussions.microsoft.com> wrote in message
news:Ox**************@TK2MSFTNGP12.phx.gbl... Yeah...
With the archetecture of ASP.NET, I imagine that the only way to preserve an object across many sessions is by creating an actual windows service that preserves the state of the object. If this were the case, then you would just have a queue of items waiting on this service, which would negate any cross-access issues. Of course, it's probably way easier to just use static functions, like stated somewhere else in this thread.
Mike
Angel wrote:
Thanks Steve, You got it right. I use something as singleton. I have one object per class. Let say my user is Student When user login I create a UserObject that I save in Session["User"]. Then on demand I fill its collection properties student classes , teachers.... Any of those collections have a class reference to a DataPersistObject instance. Every class of those collection properties has a class reference to an object (DataPersistObject ) which has only 2 methods Load(obj, id) and Save(obj), they retrieve or save one object per time from a database to collection and vice versa. The problem is that I do not know how different sessions will interact (behave) when accessing the methods of this object. Should I synchronize "Load" and "Save" methods using "lock(this)" within the methods body , or ASP.Net will take care of this concurrent access to this methods between different sessions.
When the user logout all this will be released since the only place keeping reference to this properties is UserObject, which is released when session["User is released"].
My guess is that class references to my DataPersist object would not be released until Application is running, because they have been created with Static constructor like this:
static Teachers() { //fdmobj is defined in the base class fdmobj = new DMTeacher();
}
Angel
"Steve Drake" <Steve@_NOSPAM_.Drakey.co.uk> wrote in message news:u$*************@TK2MSFTNGP09.phx.gbl...
I presume you are using a singleton pattern, I always lock when writing
and
depending on the object type lock when reading aswell.
remember, ASP.NET is stateless, yes you can create a object that sits
around
but ASP.NET could kill it when it gets recycled and you don't get any warning of this, so if you are saving things in memory that you need to
keep
then watch out.
Steve
"Angel" <an*****@hotmail.com> wrote in message news:uO**************@TK2MSFTNGP12.phx.gbl...
Hi everybody, I am new to ASP.NET, and my question might be obvious to most of you but
I
do not seem to find many things about threads and ASP.NET.
I have an object(Object 1) which need some service from another object(Object2). Object 2 has only two methods and no members.
Load(Object1 obj, int id); Save(Object1 obj);
I will have thousands instances from Object1, but to save memory I will
only
have one instance of Object2. I decided to create only one reference of Object2 and keep it as class member of Object1 class.
Now if I have only one instance per class, any user logged to the application (any session) will use the same Object2 obj2 reference. My question is: Should I make Load() and Save() methods of Object2
thread
safe(Using Lock for example), or ASP.NET will take care of different sessions(users) accessing this methods.
Again I do not create separate threads. I just wonder if ASP.NET make a separate thread for any of application users (any session) or it
creates
a
separate process(with separate allocated memory ) per session and this process memory area is guarded from other processes.
Thanks
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Ronan Viernes |
last post by:
Hi,
I have created a python script (see below) to count the maximum number
of threads per process (by starting new threads continuously until it
breaks).
######
#testThread.py
import...
|
by: Al Tobey |
last post by:
I was building perl 5.8.2 on RedHat Enterprise Linux 3.0 (AS) today and
noticed that it included in it's ccflags "-DTHREADS_HAVE_PIDS." I am
building with -Dusethreads. With newer Linux...
|
by: m |
last post by:
Hello,
I have an application that processes thousands of files each day. The
filenames and various related file information is retrieved, related
filenames are associate and placed in a linked...
|
by: Kovan Akrei |
last post by:
Hi,
I would like to know how to reuse an object of a thread (if it is possible)
in Csharp? I have the following program:
using System;
using System.Threading;
using System.Collections;
...
|
by: bygandhi |
last post by:
Hi -
I am writing a service which will check a process and its threads for
their state ( alive or dead ).
The process has 5 .net managed threads created using thread.start and
each have been...
|
by: [Yosi] |
last post by:
I would like to know how threads behavior in .NET .
When an application create 4 threads for example start all of them, the OS
task manager will execute all 4 thread in deterministic order manes,...
|
by: RahimAsif |
last post by:
Hi guys,
I would like some advice on thread programming using C#.
I am writing an application that communicates with a panel over
ethernet, collects data and writes it to a file. The way the...
|
by: mjheitland |
last post by:
Hi,
I like to know how many threads are used by a Threading.Timer object.
When I create a Threading.Timer object calling a short running method
every 5 seconds I expected to have one additional...
|
by: Darian |
last post by:
Is there a way to find all the thread names that are running in a
project?
For example, if I have 5 threads T1, T2, T3, T4, T5...and T2, T4, and
T5 are running...I want to be able to know that...
|
by: tdahsu |
last post by:
All,
I'd appreciate any help. I've got a list of files in a directory, and
I'd like to iterate through that list and process each one. Rather
than do that serially, I was thinking I should...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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,...
|
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...
|
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...
| |