Solved

Need Information on ASP.NET Application Thead Safety

Posted on 2014-09-20
1
295 Views
Last Modified: 2014-10-09
Greetings,

I will be building an ASP.NET application to process orders in a multi-user environment, and I am thinking about thread safety considerations with the class model and usage in my design.   This application will access a DB2 database on an IBM iSeries platform on the back-end, using the IBM DB2 data provider for .NET.  

In a nutshell, the page (UI) classes will create local instances of business-layer classes (order, customer, etc.), which in turn, will contain references to data-layer classes that utilize the IBM .NET data provider to read and write data.  So, the overall design of the program flow will be:
 
Web UI (page classes) --Ref--> Business Classes (DLL) --Ref--> Custom Data Layer (DLL) --Ref--> IBM .NET Data Provider --accesses-->) DB2 database (IBM i Series)
 
With this design model, I need to know what considerations should be addressed regarding thread safety, to avoid problems in a multi-user environment.  I have only a few shared public functions in a global module, but these do not affect data in any way.  They are used to perform fixed calculations or return static information from fixed lists, config file settings, etc.  
 
In my page code-behind, I'll be creating class instances that will handle the actual work and business logic.  These will be private to the page, and destroyed at the completion of the page life cycle.  Example:  The EnterOrder class (EnterOrder.aspx) references three business objects…
 
Public Class EnterOrder
    Inherits ProtectedOEWebPage   <--- (custom class; inherits from System.Web.UI.Page)
 
    Protected cobjOrder As Order    <---- (classes in referenced business object DLL)
    Protected cobjCustomer As Customer
    Protected cobjItem As Item

 
Then, in the Page_Load event, to load data for an existing order:
 
    cobjOrder = New Order()
    cobjOrder.Load(OrderID)   <-- Passed in query string for existing order
 
In the Order.Load event:

   iDB2Connection connection = new iDB2Connection(ConnectionString);   <-- from web.config
   iDB2Cmd = new iDB2Command("CALL oeGetOrder( ? )", connection);  <-- OrderID passed as input, stored procedure on IBM i Series
   iDB2DataReader driDB2Reader = iDB2Cmd.ExecuteReader();

  ... <process data reader and return record to calling function> ...


Do I need to be concerned with thread safety using this model, when multiple users are accessing the application, since business object variables are declared as protected within the page class?  Would IIS not create a separate, protected instance of each page class and referenced objects for each user session?  This application will, for the most part, be using Ajax posts to update and retrieve data, instead of page post backs. For example, user types a customer ID, and tabs out of that field.  An Ajax post is triggered, the customer ID is validated with a database call, and if valid, the ID is updated in the order table and the customer name is also refreshed on the page.  I need to ensure that this kind of end-to-end process is thread safe and without potential for conflict between users.

To summarize:

1.  Is this design thread-safe?
2.  As IIS handles multiple instances of the application and requests to read/update data from the users, will it segregate/protect instances of objects that are created for each session?
3.  If static shared functions or methods are used, should they be used sparingly, and if so, in what situations are they considered acceptable?
 
Thank you in advance.
0
Comment
Question by:bm5034
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 25

Accepted Solution

by:
apeter earned 500 total points
ID: 40356402
1. It is thread safe. You are following common practice 3tier model.
2. For each user request, there will be a separate thread to process so the object instances are safe across users.
3.static methods are thread safe by default.

Just thought will reiterate which you might have already doing.

Dispose your connection objects or any resources consumed throught the project.
Cache static values in the sever to minimise the database hits.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime is disastrous for companies and can lead to major hits on a brand, reputation, an…
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question