Multi threading

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
sandy771
Posts: 194
Joined: Tue 22 May 2007 13:57

Multi threading

Post by sandy771 » Fri 26 Nov 2010 15:57

I have a database that I want to index as a background task (the index creation process takes about 20 mins).

AT the moment I create a separte thread pass it a handle to a TUniQuery, create the indexes (about 20 of them) in the Execute method and then resume the thread.

When I do this sqlite shows that the indexes are created but when I access the database it behaves as if they have not.

I send a message when the thread terminates to indicate when the indexes have been created but this seems to return after about a minute, ether than the 20 I am expecting.

I am thinkingthat I should be createing a separate connection within the thread - would this be better?

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Post by AlexP » Mon 29 Nov 2010 11:00

Hello,

You can use a general connection for all threads.
Please try to execute the following example:

// Thread class

TIndexThread= class( TThread)
public
UniQuery: TUniQuery;
protected
procedure Execute; override;
end;

// implementation of TIndexThread

procedure TindexThread.Execute;
begin
UniQuery.ExecSQL;
self.Terminate;
end;

// creating and running the thread

var
IndexThread: TindexThread;
begin
UniQuery2.SQL.Text := 'create unique index new_index on test(id)';
IndexThread:= TindexThread.Create(true);
IndexThread.UniQuery:= UniQuery2;
IndexThread.Resume;

Post Reply