在主线程中使用 TAdsSettings 对象和在其他线程中使用 AdsQuery 对象是否安全?
我有一个 Win-CGI 应用程序,目前正在转换为 ISAPI。
该应用程序使用 Extended Systems Advantage 数据库服务器的 TDataset 后代。
由于 TAdsSettings 对象只能有一个实例,因此必须是 在主线程中。
请求线程中需要 TAdsQuery 对象。
这会起作用吗?也就是说,请求线程中的 AdsQueries 会起作用吗? 从主程序中的 AdsSettings 对象中获取全局设置 线程,这会是线程安全的吗?
I have a Win-CGI application I am currently converting to ISAPI.
The application uses the TDataset descendants for Extended Systems Advantage Database Server.
As there can be only one instance of a TAdsSettings object, this must be
in the main thread.
TAdsQuery objects are needed in the request threads.
Will this work - that is, will the AdsQueries in the request threads
pick up the global settings from the AdsSettings object in the main
thread, and will this be thread safe?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,它会起作用。 TAdsSettings 组件修改 Advantage Client Engine (ACE) 中的设置,并且通过 ISAPI,将加载所有线程使用的一个 ACE 实例。
不过,我不会推荐它。 根据您要更改的设置,直接调用 ACE API 会更有意义。 例如,如果您仅设置日期格式,则消除 TAdsSettings 组件并仅调用采用连接句柄的 AdsSetDateFormat60 更有意义。 摆脱 TAdsSettings 组件可以消除设置 ACE 全局设置的大量调用。 其中许多调用必须有一个同步对象,以在全局更改时保持所有连接关闭。 这会对性能产生负面影响,尤其是在 Web 应用程序等多线程应用程序中。 而是进行对指定连接句柄进行操作的调用。
您可以通过引用 TAdsConnection.Handle 属性或调用 TAdsQuery.GetAceConnectionHandle 方法来获取连接句柄。
Yes, it will work. The TAdsSettings component modifies settings in the Advantage Client Engine (ACE), and with ISAPI there will be one instance of ACE loaded that all threads use.
I wouldn't recommend it, however. Depending on the settings you are changing it would make more sense to just call the ACE APIs directly. For example, if you are only setting the date format, it makes more sense to eliminate the TAdsSettings component and just call AdsSetDateFormat60, which takes a connection handle. Getting rid of the TAdsSettings component eliminates lots of calls to set ACE global settings. Many of those calls have to have a sync object to hold all connections off while the global is changed. That will have a negative performance impact, especially in a multi-threaded application like a web application. Instead make calls that operate on the specified connection handle.
You can get the connection handle by referencing the TAdsConnection.Handle property or calling the TAdsQuery.GetAceConnectionHandle method.
如果 AdsQueries 不在主线程中(即
System.MainThreadID <>),请确保 AdsQueries 使用 Synchronize 直接访问 TAdsSettings(或使用消息系统在工作线程和主线程之间进行通信,而不是直接访问)。 Windows.GetCurrentThreadID
)Make sure the AdsQueries use Synchronize to access the TAdsSettings directly (or use a messaging system to comunicate between worker threads and main thread instead of accessing directly) if they are not in the main thread (i.e.
System.MainThreadID <> Windows.GetCurrentThreadID
)我还在新闻组中提出了这个问题:devzone.advantagedatabase.com,Advantage.Delphi
为了完整起见,我将添加该线程其余部分的进一步问题/答案:
因此,从 Jeremy 的回答来看,最好为每个线程创建至少一个 TAdsConnection 对象,并确保所有查询都附加到它,否则可能会发生序列化。
I also had asked this question in the newsgroup: devzone.advantagedatabase.com, Advantage.Delphi
For the sake of completeness, I'll add further question/answer from the rest of that thread:
Thus, from Jeremy's answer it is best to create at least one TAdsConnection object for each thread and ensure that all queries are attached to it, otherwise serialization may occur.