Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- uses Diagnostics, Threading, InterbaseUniProvider, System.TimeSpan;
- procedure SetupConnection(const AUniConn: TUniConnection);
- begin
- AUniConn.ProviderName := 'InterBase';
- AUniConn.Server :='localhost';
- AUniConn.Database := 'employee';
- AUniConn.Username := 'SYSDBA';
- AUniConn.Password := 'masterkey';
- AUniConn.LoginPrompt := False;
- AUniConn.PoolingOptions.MaxPoolSize := 100;
- AUniConn.PoolingOptions.MinPoolSize := 2;
- AUniConn.PoolingOptions.ConnectionLifetime := 60000; // 60 seconds
- AUniConn.PoolingOptions.Validate := True;
- AUniConn.Pooling := True;
- end;
- procedure TForm1.Button1Click(Sender: TObject);
- var
- LIndex: Integer;
- LStopWatch: TStopWatch;
- LTasks: TArray<ITask>;
- begin
- LStopWatch := TStopWatch.StartNew;
- LTasks := [];
- for LIndex := 1 to 1000 do
- begin
- LTasks := LTasks + [
- TTask.Run(
- procedure
- var
- LConnection: TUniConnection;
- LQuery: TUniQuery;
- begin
- LConnection := TUniConnection.Create(nil);
- try
- SetupConnection(LConnection);
- LQuery := TUniQuery.Create(nil);
- try
- LQuery.Connection := LConnection;
- LQuery.SQL.Text := 'select * from EMPLOYEE';
- LQuery.Open;
- LQuery.Last;
- finally
- FreeAndNil(LQuery);
- end;
- finally
- FreeAndNil(LConnection);
- end;
- end
- )
- ];
- end;
- TTask.WaitForAll(LTasks);
- LStopWatch.Stop;
- Button1.Caption := LStopWatch.ElapsedMilliseconds.ToString;
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement