Multithreaded Insert
Moderators: gto, cipto_kh, EgonHugeist
Multithreaded Insert
Hello,
I want to change my application to run multithreaded.
Right now I am using zeos and firebird. It inserts data sets in
a sequential way into database.
In general this could be done in parallel. But I wonder if zeos supports
this?
Sequence:
Insert;
dataset.fieldbyname('xxx')=xxx;
post;
How can this be done threadsafe?
Thanks!
I want to change my application to run multithreaded.
Right now I am using zeos and firebird. It inserts data sets in
a sequential way into database.
In general this could be done in parallel. But I wonder if zeos supports
this?
Sequence:
Insert;
dataset.fieldbyname('xxx')=xxx;
post;
How can this be done threadsafe?
Thanks!
-
- Expert Boarder
- Posts: 158
- Joined: 06.11.2005, 01:43
-
- Expert Boarder
- Posts: 158
- Joined: 06.11.2005, 01:43
Hi Andreas
You will have to declare a function that takes care of managing and returning a connection TO and FROM the Pool. There should be some docs on the web on this topic.
So in your thread you could do something like
lZCon := GetConFromPool;
try
// Assign connection to all your controls that connect to database.
finally
ReturnConToPool(lZCon);
end;
This is the basic structure that I have used in my apps and has worked fine for me.
Hope that helps.
Regards
Sandeep
You will have to declare a function that takes care of managing and returning a connection TO and FROM the Pool. There should be some docs on the web on this topic.
So in your thread you could do something like
lZCon := GetConFromPool;
try
// Assign connection to all your controls that connect to database.
finally
ReturnConToPool(lZCon);
end;
This is the basic structure that I have used in my apps and has worked fine for me.
Hope that helps.
Regards
Sandeep
It would do the trick, but with a connection pool you'll have some persistent connections available, loosing the weight of connection and disconnecting in all threads.r2d2 wrote:Hi Sandeep,
would it also work to do a connection.create() and a
freeandnil(connection) in each thread?
Thx
Andreas
Well, you get the idea.
-
- Expert Boarder
- Posts: 158
- Joined: 06.11.2005, 01:43
The app has the following db design:
Main: TZCon1->TZQuery1->TDataSource->DBGrid
it issues threads with the following structure
Threadn: TZCon2->TZQuery2->insert/update/...
While running the threads work but Main doesnt update.
After close and restart of Main I get all records displayed in DBGrid.
Is this a buffer problem? Or invalidate/update problem?
Regards
Andreas
Main: TZCon1->TZQuery1->TDataSource->DBGrid
it issues threads with the following structure
Threadn: TZCon2->TZQuery2->insert/update/...
While running the threads work but Main doesnt update.
After close and restart of Main I get all records displayed in DBGrid.
Is this a buffer problem? Or invalidate/update problem?
Regards
Andreas