Advantage Developer Zone

 
 
 

Building Multi-threaded Applications with Advantage

Friday, July 14, 2006

Starting with Advantage Database Engine, version 2.6, table and query handles may be used across threads.

Building Multi-Threaded Applications with TAdsQuery and TAdsTable

An Advantage TAdsQuery instance can be dropped on to a TDataModule (owned by the main application thread) and used within a secondary thread to execute a query. Unlike the BDE, TSession is not used in any part of the Advantage TDataSet Descendant solution. The table or query component is simply referenced or created in the TThread.Execute body.

The Advantage TAdsConnection.AdsServerTypes property allows the Advantage server type (Remote, Local, Internet) to be associated with a specific connection. This is useful when the application uses more than one server type. TAdsConnection components may be created either in the main thread by placing them on a TForm or TDataModule, or in the TThread.Execute body.

When building multi-threaded applications, it is important to note that all requests to any table or index associated to a single connection are synchronized. If multiple threads try to use a single connection simultaneously, all threads but one will be paused until the one has completed its task. If that task takes a long time, such as a lengthy SQL query or building an index, the other threads may be paused for an unacceptable time. To prevent threads from being paused, use separate TAdsConnection instances for any TAdsTable or TAdsQuery instances that will be used to perform operations that may take considerable time.