Single or multiple thread?

  • Thread starter Thread starter Andrea
  • Start date Start date
A

Andrea

Suppose a base class like

partial class X : Page ...

and a class A that is called from class X somewhere along the code.

I'm not able to understand if for each user connected to the web site, a
thread is created and so every call to class A stay in different thread or
all works into a single thread.

I'm asking this because I've a function the get the last ID of a table in
the db, but I'm worried about that multiple call can return the same number
at same time (since I just get the number) and after I increment it.

What could be a solution? In a multiple thread scenario, the lock statement
sounds good ... but I'm not sure about the scenario it represents.

Thanks
Andrea
 
there is a thread for each current request, with one exception. only one
active request per session is allowed (others are queued). also during the
processing of the page, the request thread may change.

if you use static data (shared across threads) then you must use locking. in
your example, you need to do some sort of locking, as if two users insert at
the same time, they can both get the id back. you can lock in your aspx code
(not the best), or you can lock at the database level if you are using a
database like db2, sqlserver or oracle, though the techique will be
different for each.

-- bruce (sqlwork.com)
 
Hello Bruce,

Thanks, unfortunately, actually I'm on access, so the only lock I can use
is over asp.net.

But when I'll develop the DL for SQL server, I'll use the lock on the DB.

Bye
Andrea
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top