After creating an application with one or more data modules, you finally
end up by using the global variable of the data module to simplify the data
access (in my case 160 units works with data acces).
I understand that this is not the way we have to handle multi threading - so
the question is:
Is it safe to define the data modules global variable as threadvar ?
Off course this instance will be created for each thread - for example in
the TWebModule constructor or OnCreate event.
Thank in advance
Jacques Garcia Vazquez
"Jacques Garcia Vazquez" <j...@FlexsysBelgium.com> wrote in message
news:3c848fa0_2@dnews...
Thanks for the info but in that case I have to rewrite all my units (160 =
lot of work and late in time) !
By the way this is also the way I want to go, create the datamodule in the
constructor, and free it in the destructor. The only difference is that the
created datamodule in not a member of the webmodule object but is attached
to a threadvar so that available to all referenced units. I only suspect
some problems arround this way - do you have more info about the threadvar ?
Jacques Garcia Vazquez
"Corbin Dunn" <cd...@no.spam.borland.com> wrote in message
news:3c851149$1_2@dnews...
I asked this question about 2 weeks ago (19/02, titled Double click strange
happenings - this was followed up by some private email from other
parties)......
I had the exact same design as you which worked fine on my local server with
only me using the unit. When I uploaded the unit onto the test system it
worked fine until I clicked a form submit button more than once. This
resulted in my data module losing connection to the db. I was also
dynamically populating a query at runtime but when this happened my SQL was
cleared. I firstly had my DM as a global variable. I then changed it to a
private instance variable of the isapi which cured some of the problems but
not all.
Anyway, the end result was that ISAPI modules can't work in conjunction with
data modules safely (I was advised). I know they appear to work but I was
advised that my problems were due to the use of the data module, as they do
not multi thread in the same way as the isapi. I removed the DM and sure
enough everything works fine!
I know this isn't what you want to hear - i've been there! If anyone else
has another angle on this I would be interested.
If you need any more please feel free to reply.
Regards
Will
"Jacques Garcia Vazquez" <j...@FlexsysBelgium.com> wrote in message
news:3c848fa0_2@dnews...
William,
I'm not sure who "advised" you :), but I have been using Data Modules
with WebModules for ages without a problem. In fact, most of my objects
reside in DataModules as well ALL data Access (I have different data
access modules for different databases/data access methods that are
compiled using compiler directives). My Web Modules are data access
agnostic.
Other data access, my other data modules have various business related
functionality including custom business objects.
What's the difference between having a Data Module (as a
member/property) of the WebModule and say a PageProducer? They are both
members of the Web Module.
Yes, declaring a Data Module as a global variable will cause a lot of
grief! This is so, because "global" variables are shared across threads
and as such access to them MUST be serialized.
--
Shiv Kumar
The Delphi Apostle
http://www.matlus.com
http://www.delphisoap.com
If you must have your data modules as global threadvars I would suggest
creating them as singletons. There is no point having a global variable
in a multi-threaded application that is created for each thread
instance.
You might want to have a global threadsafe list (where the list is
declared as a var in the global section) and ensuring a single instance
of this list. The list in turn contains instances of each of your Data
Modules. You shouldn't have to change your DataModules to do this.
However, sharing your DataModules across threads is bound to impact
(quite heavily) your performance, since every thread will potentially
have to wait on other threads to finish before it can use the data
Modules. Effectively, you're using a single threaded application!
Well, first thanks for your answer.
But this sound strange and I would be very interrested to know why a datamod
can't works safely with a webmodule.
When looking at the source code, it seems that only one thread access one
webmodule at a time so normally every think is fine if you have a session
(not shared) per datamodule.
On the other side, I would be very interrested to know if someone had
created a web app over an existing -big- application without having to
rewrite all data acces part. The object concept was also done to have
reusability and if you can't reuse existing object in the web app this is a
BIG problem.
Regards
Jacques
"William Buchanan" <william....@bdml.co.uk> wrote in message
news:3c85dda3$1_1@dnews...
function MyDatamodule: tMyDataModule;
begin
Result := MySingletonList.find (GetCurrentThreadID);
assert (result <> nil);
end;
Then in the constructor of the webmodule I can add my datamodule(s)
MySingletonList.Add (MyDataModule.Create) and free them in the destructor.
This will certainly works - I don't have tested it yet.
Anyway thanks for your help.
Regards
Jacques
"Shiv Kumar" <shivk...@erols.com> wrote in message
news:3c85f36d$1_2@dnews...
Regards
Will
"Shiv Kumar" <shivk...@erols.com> wrote in message
news:3c85f206$1_2@dnews...
I think I remember your case :)
>global variable trap (you advised me on that one!),
Did I ask you to use a global variable or advised you against it ? :).
You must have been doing thing wrong. There is no need to treat a
DataModule (or modules) any different to a regular component you drop on
a WebModule.
At the same time, They all behave like a WebModule, in that, they all
seem to be "brain dead" after satisfying a response, so the next time
around you've got to make sure things are "reset/initialized".
> Did I ask you to use a global variable or advised you against it ? :).
Advised against.
> At the same time, They all behave like a WebModule, in that, they all
> seem to be "brain dead" after satisfying a response, so the next time
> around you've got to make sure things are "reset/initialized".
This could possibly explain it although most of the initialising takes place
in the web module create event which was being fired correctly.
Will take another look I think!
Regards
Will
If you're creating a list of data Modules per web module/thread, then
you don't need to have access to them serialized :)
Either you have each data Module as a member/property of the WebModule
class (create them and destroy them yourself or let the WebModule
destroy them if it is the owner).
or
Have a global thread safe, singleton list (that holds each of your data
modules). That is only one instance is shared across threads.
http://www.midwayusa.com
- 100% Delphi CGI
Add a few items to your cart and get a shipping quote. The datamodule that
calculates shipping charges is the exact same one our contact center
associates use while placing (phone) orders (standard windows app). Address
verification module, shopping cart module, are all shared between web
applications. Only the shopping cart module is created on startup (declared
in the Private section) of the CGI app, everything else is create/destroyed
on an as-needed basis (like tag/action events, declared locally in that
procedure)
Good luck,
krf
Jacques Garcia Vazquez <j...@FlexsysBelgium.com> wrote in message
news:3c85f64a_2@dnews...
"Kevin Frevert" <kfre...@midwayusa.com> wrote in message
news:3c864737$1_1@dnews...
As I already mentioned, I highly reccomend doing the above. Otherwise, you
are going to have performance issues.
.corbin
so what I will do is to replace the global variable with a function that
will return a per thread data module.
Jacques
"Shiv Kumar" <shivk...@erols.com> wrote in message
news:3c86240c$1_2@dnews...